{"id":428,"date":"2009-07-06T22:24:49","date_gmt":"2009-07-06T15:24:49","guid":{"rendered":"http:\/\/adityo.blog.binusian.org\/?p=428"},"modified":"2009-07-15T19:03:45","modified_gmt":"2009-07-15T12:03:45","slug":"how-to-install-php-fpm-nginx-on-centos-53","status":"publish","type":"post","link":"https:\/\/adityo.blog.binusian.org\/?p=428","title":{"rendered":"How to install PHP-fpm + Nginx on CentOS 5.3"},"content":{"rendered":"<p style=\"text-align: justify;\"><span style=\"font-family: -webkit-monospace;\">In this tutorial i will try to install php-fpm with nginx on centos 5.3. But first:<\/span><\/p>\n<h2 style=\"text-align: justify;\"><span style=\"font-size: x-large;\">What is PHP-FPM ?<\/span><\/h2>\n<p style=\"text-align: justify; \">PHP-FPM is a patch for PHP4\/5 to greatly improve PHP&#8217;s FastCGI SAPI capabilities and administration. This means that you don\u2019t install php through your distribution\u2019s package manager, but rather download the package from the PHP-website, and the patch from another site. You patch up the sourcecode, compile things, and get it started.<\/p>\n<p style=\"text-align: justify; \">\n<p>The following is a comparison chart of problems and how php-fpm handles them, when enabled with the FastCGI SAPI:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"20\">\n<tbody>\n<tr>\n<th>Description<\/th>\n<th>php &#8220;out of the box&#8221;<\/th>\n<th>spawn-fcgi + spawn-php.sh + daemontools<\/th>\n<th>php-fpm<\/th>\n<\/tr>\n<tr>\n<td>php daemonization: pid file, log file, setsid(), setuid(), setgid(), chroot()<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Process Management. Ability to &#8220;graceful&#8221; stop and start php workers without losing any queries. The possibility of gradually update the configuration and binary without losing any queries.<\/td>\n<td>php4 (-), php5 (only graceful completion)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Restricting ip addresses from which requests can come from a web server<\/td>\n<td>php4 (-), php5 (+) (from 5.2.2)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Dynamic number of processes, depending on the load<\/td>\n<td>(-)<\/td>\n<td>(-)<\/td>\n<td>TODO<\/td>\n<\/tr>\n<tr>\n<td>Starting the workers with different uid\/gid\/chroot\/environment and different php.ini option. You do not need a safe mode!<\/td>\n<td>(-)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Logging stdout &amp; stderr business processes<\/td>\n<td>(-)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Emergency restart all the processes in the event of accidental destruction of shared memory opcode cache, if used accelerator<\/td>\n<td>(-)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<tr>\n<td>Forcing the completion of process if set_time_limit() fails<\/td>\n<td>(-)<\/td>\n<td>(-)<\/td>\n<td>(+)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Compare to spawn- fastcgi installation , php-fpm installation is much slower and you can refer to\u00a0<a href=\"http:\/\/www.cyberciti.biz\/faq\/rhel-fedora-install-configure-nginx-php5\/\" target=\"_blank\">http:\/\/www.cyberciti.biz\/faq\/rhel-fedora-install-configure-nginx-php5\/<\/a> for spawn-fcgi installation. Okay let&#8217;s start the installation.<\/p>\n<p>Installation<\/p>\n<p>1. Install some dependecies first<br \/>\n<code># yum install gcc libjpeg-devel libpng-devel libmcrypt libmcrypt-devel pcre pcre-devel<\/code><\/p>\n<p>2. We need to get\u00a0PHP-sourcecode and php-fpm patch, in this tutorial i use\u00a0php-5.2.10 and\u00a0php-5.2.10-fpm-0.5.13<br \/>\n<code># wget http:\/\/id.php.net\/get\/php-5.2.10.tar.bz2\/from\/us.php.net\/mirror<\/code><br \/>\n<code>wget http:\/\/php-fpm.org\/downloads\/php-5.2.10-fpm-0.5.13.diff.gz<\/code><\/p>\n<p>3. Extract and run the patch<br \/>\n<code># tar xvf php-5.2.10.tar.bz2<\/code><br \/>\n<code># gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1<\/code><\/p>\n<p>4. Configure and compile cd php-5.2.10 and hp-5.2.10-fpm-0.5.13 patch<br \/>\n<code># .\/configure --enable-fastcgi --enable-fpm --with-mcrypt --enable-mbstring --enable-mysql --with-mysql=\/usr\/include\/mysql --with-mysql-sock=\/tmp\/mysql.sock --with-curl --with-sockets --with-gd --with-zlib --with-iconv --with-dom --with-jpeg-dir=\/usr\/lib<\/code><br \/>\n<code>make<\/code><br \/>\n<code>make install <\/code><\/p>\n<p>You should see this on the end of installation<\/p>\n<p><code><br \/>\nInstalling PHP SAPI module:       cgi<br \/>\nInstalling PHP CGI binary: \/usr\/local\/bin\/<br \/>\nInstalling FPM config:            \/usr\/local\/etc\/php-fpm.conf<br \/>\n(installing as php-fpm.conf.default)<br \/>\nInstalling init.d script:         \/usr\/local\/sbin\/php-fpm<br \/>\nInstalling PHP CLI binary:        \/usr\/local\/bin\/<br \/>\nInstalling PHP CLI man page:      \/usr\/local\/man\/man1\/<br \/>\nInstalling build environment:     \/usr\/local\/lib\/php\/build\/<br \/>\nInstalling header files:          \/usr\/local\/include\/php\/<br \/>\n^[[BInstalling helper programs:       \/usr\/local\/bin\/<br \/>\nprogram: phpize<br \/>\nprogram: php-config<br \/>\nInstalling man pages:             \/usr\/local\/man\/man1\/<br \/>\npage: phpize.1<br \/>\npage: php-config.1<br \/>\nInstalling PEAR environment:      \/usr\/local\/lib\/php\/<br \/>\npear\/pear dependency package \"pear\/Archive_Tar\" installed version 1.3.3 is not the recommended version<br \/>\n1.3.2, but may be compatible, use --force to install<br \/>\npear\/Archive_Tar cannot be installed, conflicts with installed packages<br \/>\n[PEAR] Archive_Tar    - upgraded:  1.3.3<br \/>\n[PEAR] Console_Getopt - already installed: 1.2.3<br \/>\n[PEAR] Structures_Graph- already installed: 1.0.2<br \/>\n[PEAR] XML_Util       - installed: 1.2.1<br \/>\n[PEAR] PEAR           - upgraded:  1.8.0<br \/>\nWrote PEAR system config file at: \/usr\/local\/etc\/pear.conf<br \/>\nYou may want to add: \/usr\/local\/lib\/php to your php.ini include_path<br \/>\nInstalling PDO headers:          \/usr\/local\/include\/php\/ext\/pdo\/<\/code><\/p>\n<p>5. Installing Init Script for PHP-FPM<br \/>\n<code># cd \/etc\/init.d\/<br \/>\n# ln -s \/usr\/local\/sbin\/php-fpm php-fpm<\/code><\/p>\n<p>add this to \/etc\/rc.local if you want php-fpm to start from booting<br \/>\n<code># vi \/etc\/rc.local<\/code><br \/>\n<code>\/etc\/init.d\/php-fpm start<\/code><\/p>\n<p style=\"text-align: justify;\">\n<p>6. Installing and configure  nginx, when i write this tutorial the latest stable versions are nginx-0.7.61 you can go to <a href=\"http:\/\/nginx.net\/\">http:\/\/nginx.net\/<\/a> for latest nginx sourcode<br \/>\n<code>wget http:\/\/sysoev.ru\/nginx\/nginx-0.7.61.tar.gz<\/code><br \/>\n<code>tar xvf http:\/\/sysoev.ru\/nginx\/nginx-0.7.61.tar.gz<\/code><br \/>\n<code>cd nginx-0.7.61<\/code><br \/>\n<code>.\/configure --pid-path=\/usr\/local\/nginx\/logs\/nginx.pid --sbin-path=\/usr\/local\/sbin\/nginx --with-md5=\/usr\/lib --with-sha1=\/usr\/lib --with-http_ssl_module  --with-http_dav_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module<\/code><br \/>\n<code># make <\/code><br \/>\n<code># make install <\/code><\/p>\n<p>7. Installing  Nginx Daemon for CentOS, you can copy paste this script to your \/etc\/init.d\/nginx<br \/>\n<code><br \/>\n#! \/bin\/sh<br \/>\n### BEGIN INIT INFO<br \/>\n# Provides:          skeleton<br \/>\n# Required-Start:    $local_fs $remote_fs<br \/>\n# Required-Stop:     $local_fs $remote_fs<br \/>\n# Default-Start:     2 3 4 5<br \/>\n# Default-Stop:      S 0 1 6<br \/>\n# Short-Description: Example initscript<br \/>\n# Description:       This file should be used to construct scripts to be<br \/>\n#                    placed in \/etc\/init.d.<br \/>\n### END INIT INFO<br \/>\n#<br \/>\n# Author:       Ryan Norbauer<br \/>\n#<br \/>\nset -e<br \/>\nPATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin<br \/>\nDESC=\"nginx daemon\"<br \/>\nNAME=nginx<br \/>\nDAEMON=\/usr\/local\/sbin\/$NAME<br \/>\nPIDFILE=\/usr\/local\/nginx\/logs\/$NAME.pid<br \/>\nSCRIPTNAME=\/etc\/init.d\/$NAME<br \/>\n# Gracefully exit if the package has been removed.<br \/>\ntest -x $DAEMON || exit 0<br \/>\n# Read config file if it is present.<br \/>\n#if [ -r \/etc\/default\/$NAME ]<br \/>\n#then<br \/>\n#       . \/etc\/default\/$NAME<br \/>\n#fi<br \/>\n#<br \/>\n#       Function that starts the daemon\/service.<br \/>\n#<br \/>\nd_start() {<br \/>\nstart-stop-daemon --start --quiet --pidfile $PIDFILE \\<br \/>\n--exec $DAEMON \\<br \/>\n|| echo -n \" already running\"<br \/>\n}<br \/>\n#<br \/>\n#       Function that stops the daemon\/service.<br \/>\n#<br \/>\nd_stop() {<br \/>\nstart-stop-daemon --stop --quiet --pidfile $PIDFILE \\<br \/>\n--name $NAME \\<br \/>\n|| echo -n \" not running\"<br \/>\n}<\/code><\/p>\n<p><code>#<br \/>\n#       Function that sends a SIGHUP to the daemon\/service.<br \/>\n#<br \/>\nd_reload() {<br \/>\nstart-stop-daemon --stop --quiet --pidfile $PIDFILE \\<br \/>\n--name $NAME --signal 1<br \/>\n}<\/code><\/p>\n<p><code> <\/code><code>case \"$1\" in<br \/>\nstart)<br \/>\necho -n \"Starting $DESC: $NAME\"<br \/>\nd_start<br \/>\necho \".\"<br \/>\n;;<br \/>\nstop)<br \/>\necho -n \"Stopping $DESC: $NAME\"<br \/>\nd_stop<br \/>\necho \".\"<br \/>\n;;<br \/>\n#reload)<br \/>\n#<br \/>\n#       If the daemon can reload its configuration without<br \/>\n#       restarting (for example, when it is sent a SIGHUP),<br \/>\n#       then implement that here.<br \/>\n#<br \/>\n#       If the daemon responds to changes in its config file<br \/>\n#       directly anyway, make this an \"exit 0\".<br \/>\n#<br \/>\n# echo -n \"Reloading $DESC configuration...\"<br \/>\n# d_reload<br \/>\n# echo \"done.\"<br \/>\n#;;<br \/>\nrestart|force-reload)<br \/>\n#<br \/>\n#       If the \"reload\" option is implemented, move the \"force-reload\"<br \/>\n#       option to the \"reload\" entry above. If not, \"force-reload\" is<br \/>\n#       just the same as \"restart\".<br \/>\n#<br \/>\necho -n \"Restarting $DESC: $NAME\"<br \/>\nd_stop<br \/>\n# One second might not be time enough for a daemon to stop,<br \/>\n# if this happens, d_start will fail (and dpkg will break if<br \/>\n# the package is being upgraded). Change the timeout if needed<br \/>\n# be, or change d_stop to have start-stop-daemon use --retry.<br \/>\n# Notice that using --retry slows down the shutdown process somewhat.<br \/>\nsleep 1<br \/>\nd_start<br \/>\necho \".\"<br \/>\n;;<br \/>\n*)<br \/>\necho \"Usage: $SCRIPTNAME {start|stop|restart|force-reload}\" &gt;&amp;2<br \/>\nexit 3<br \/>\n;;<br \/>\nesac<br \/>\nexit 0<br \/>\n<\/code><\/p>\n<p>Or you can download it from http:\/\/www.magnet-id.com\/download\/nginx\/nginx-daemon<br \/>\n<code>wget http:\/\/www.magnet-id.com\/download\/nginx\/nginx-daemon -O \/etc\/init.d\/nginx<\/code><br \/>\nand don&#8217;t forget to set the permission<br \/>\n<code># chmod 750 \/etc\/init.d\/nginx<\/code><\/p>\n<p>Install start-stop-daemonvand add nginx on the start up<br \/>\n<code><br \/>\nwget http:\/\/www.magnet-id.com\/download\/nginx\/apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz<br \/>\ntar zxvf apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz<br \/>\ncd apps\/sys-utils\/start-stop-daemon-IR1_9_18-1\/<br \/>\ngcc start-stop-daemon.c -o start-stop-daemon<br \/>\ncp start-stop-daemon \/usr\/sbin<br \/>\nchkconfig --add nginx<br \/>\nchkconfig --level 345 nginx on<br \/>\n<\/code><\/p>\n<p>Nginx.conf configuration<\/p>\n<p>go to nginx configuration file: &#8220;\/usr\/local\/nginx\/conf\/nginx.conf&#8221; , and add the php configuration<br \/>\n<code><br \/>\nlocation ~ \\.php$ {<br \/>\nroot           \/usr\/share\/nginx\/html;  # itmena the root of the coument are located on  \/usr\/share\/nginx\/html<br \/>\nfastcgi_pass   127.0.0.1:9000;<br \/>\nfastcgi_index  index.php;<br \/>\nfastcgi_param  SCRIPT_FILENAME  \/usr\/share\/nginx\/html$fastcgi_script_name;<br \/>\ninclude        fastcgi_params;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Go to  \/usr\/share\/nginx\/html and create php files<br \/>\n<code># vi index.php<br \/>\n&lt;? phpinfo(); ?&gt;<\/code><\/p>\n<p>8. Start the nginx and php-fpm<br \/>\n<code># service php-fpm start<\/code><br \/>\n<code># service nginx start <\/code><br \/>\n9. You should go to your domain or server address and see the phpinfo<\/p>\n<p><a href=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-440\" title=\"php-fpm1\" src=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm1.png\" alt=\"php-fpm1\" width=\"481\" height=\"60\" srcset=\"https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm1.png 601w, https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm1-300x37.png 300w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-441\" title=\"php-fpm2\" src=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm2.png\" alt=\"php-fpm2\" width=\"482\" height=\"66\" srcset=\"https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm2.png 603w, https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm2-300x40.png 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-442\" title=\"php-fpm3\" src=\"http:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm3.png\" alt=\"php-fpm3\" width=\"482\" height=\"90\" srcset=\"https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm3.png 603w, https:\/\/adityo.blog.binusian.org\/files\/2009\/07\/php-fpm3-300x56.png 300w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial i will try to install php-fpm with nginx on centos 5.3. But first: What is PHP-FPM ? PHP-FPM is a patch for PHP4\/5 to greatly improve PHP&#8217;s FastCGI SAPI capabilities and administration. This means that you don\u2019t install php through your distribution\u2019s package manager, but rather download the package from the PHP-website, [&hellip;]<\/p>\n","protected":false},"author":386,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1887,891],"tags":[2506],"class_list":["post-428","post","type-post","status-publish","format-standard","hentry","category-nginx","category-php","tag-php-fpm-nginx"],"_links":{"self":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/users\/386"}],"replies":[{"embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=428"}],"version-history":[{"count":32,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/428\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=\/wp\/v2\/posts\/428\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adityo.blog.binusian.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}