1. Installing nginx:http://www.cnblogs.com/vurtne-lu/p/7010065.html
2. Compiling the installation
[[email protected] opt]# wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror[[email Protected] opt]# MV Mirror php-5.5.35.tar.gz[[email protected] opt]# tar-zxvf php-5.5.35.tar.gz [[email Protected] opt]# CD php-5.5.35[[email protected] php-5.5.35]#./configure--prefix=/usr/local/product/ php-5.5.35--with-config-file-path=/usr/local/product/php-5.5.35/etc--with-bz2--with-curl--enable-ftp --enable-sockets--disable-ipv6--with-gd--with-jpeg-dir=/usr/local--with-png-dir=/usr/local--wi Th-freetype-dir=/usr/local--enable-gd-native-ttf--with-iconv-dir=/usr/local--enable-mbstring--enable-c Alendar--with-gettext--with-libxml-dir=/usr/local--with-zlib--with-pdo-mysql=mysqlnd--with-mysqli =mysqlnd--with-mysql=mysqlnd--enable-dom--enable-xml--enable-fpm--with-libdir=lib64--enable- Bcmath[[email protected] php-5.5.35]# make &&Make install[[email protected] php-5.5.35]# ln-s/usr/local/product/php-5.5.35/usr/local/php[[email Protected] php-5.5.35]# CP php.ini-production/usr/local/php/etc/php.ini[[email protected] php-5.5.35]# cd/usr/ Local/php/etc/[[email protected] php-5.5.35]# CP php-fpm.conf.default php-fpm.conf
3. Start PHP-FPM
[Email protected] etc]#/USR/LOCAL/PRODUCT/PHP-5.5.35/SBIN/PHP-FPM [[email protected] etc]# netstat-tunlptcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
4. Add service Management and write the startup script:
[[email protected] ~]# vim/etc/rc.d/init.d/php-fpm#! /bin/sh### BEGIN INIT info# provides:php-fpm# required-start: $remote _fs $network # required-stop: $remote _fs $network # default-start:2 3 4 AA default-stop:0 1 6# short-description:starts php-fpm# Description: Starts the PHP FastCGI Process Manager daemon### END INIT infoprefix=/usr/local/phpexec_prefix=${prefix}php_fpm_bin=${ Exec_prefix}/sbin/php-fpmphp_fpm_conf=${prefix}/etc/php-fpm.confphp_fpm_pid=${prefix}/var/run/php-fpm.pidphp_ opts= "--fpm-config $php _fpm_conf--pid $php _fpm_pid" Wait_for_pid () {try=0 while Test $try-lt; "$" in ' created ') if [-F "$"]; Then try= "Break fi;; ' Removed ') if [!-F "$"]; Then try= "Break fi;; Esac Echo-n. try= ' expr $try + 1 ' sleep 1 done}case "$1 "in Start" echo-n "Starting php-fpm" $php _fpm_bin--daemonize $php _opts if ["$?"! = 0]; Then echo "Failed" Exit 1 fi wait_for_pid created $php _fpm_pid if [-N "$try" ] ; Then echo "Failed" Exit 1 else echo ' done ' fi;; Stop) echo-n "Gracefully shutting down php-fpm" if [! -R $php _fpm_pid]; Then echo "Warning, no PID file found-php-fpm are not running?" Exit 1 fi kill-quit ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pid if [-N ' $try]; Then echo "failed. Use Force-quit "Exit 1 else echo" done "FI;; status) if [!-R $php _fpm_pid]; Then echo "PHP-FPM is stopped" Exit 0 fi pid= ' cat $php _fpm_pid ' if ps-p $PID | Grep-q $PID; Then Echo ' PHP-FPM (PID $PID) is running..." else echo "php-fpm dead but PID file exists" FI; Force-quit) echo-n "terminating php-fpm" if [! -R $php _fpm_pid]; Then echo "Warning, no PID file found-php-fpm are not running?" Exit 1 fi kill-term ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pid if [-N ' $try]; Then echo "Failed" Exit 1 else echo ' done ' fi;; Restart) $ stop $ start; Reload) echo-n "Reload service php-fpm" if [! -R $php _fpm_pid]; Then echo "Warning, no PID file found-php-fpm are not running?" Exit 1 fi kill-usr2 ' cat $php _fpm_pid ' echo ' done ';; *) echo "Usage: $ Start|stop|force-quit|restart|reload|status}" exit 1;; Esac
5. Add Launch Permissions
[Email protected] ~]# chmod +x/etc/rc.d/init.d/php-fpm
6. Add to Chkconfig management, set up with system boot
[Email protected] ~]# chkconfig--add php-fpm #php-fpm Join service [[email protected] ~]# chkconfig php-fpm on #php-fpm 2 Level 34 set to start [[email protected] ~]# chkconfig--list php-fpmphp-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off # View PHP-FPM Service Current configuration
7. How to use the service
[[Email protected] ~]# service PHP-FPM start # startup [[email protected] ~]# service php-fpm Stop # close [Email protect ED] ~]# Service php-fpm restart # reboot [[email protected] ~]# service php-fpm Reload # reload [[email protected] ~]# ser Vice PHP-FPM configtest #检查配置文件
8. Configure the test Site
[Email protected] ~]# mkdir/data/web/zabbix.lifec.com-p[[email protected] ~]# mkdir/data/logs/nginx/-p[[email Protec Ted] ~]# Mkdir/data/logs/zabbix[[email protected] ~]# vim/data/web/zabbix.lifec.com/info.php <?php phpinfo ();? >
9. Configuring the nginx.conf configuration file
[email protected] conf]# cat Nginx.confuser nginx;worker_processes 1; #error_log Logs/error.log Warning ; #error_log logs/error.log notice; #error_log logs/error.log info;pid logs/nginx.pid;events { worker_connections 1024;} HTTP { include mime.types; Default_type Application/octet-stream; Log_format main ' $remote _addr-$remote _user [$time _local] "$request" " $status $body _bytes_sent" $ Http_referer " " "$http _user_agent" "$http _x_forwarded_for"; Access_log logs/access.log main; Sendfile on ; #tcp_nopush on ; #keepalive_timeout 0; Keepalive_timeout ; #gzip on ; Include extra/*.conf;}
10. Edit Nginx Virtual Host
[Email protected] conf]# pwd/usr/local/product/nginx-1.9.15/conf[[email protected] conf]# mkdir extra[[email Protected] conf]# CD Extra[[email protected] conf]# vim nginx.conf server {Listen 8027;server_name zabbix.lifec.com;acces S_log/data/logs/zabbix/zabbix.lifec.com.access.log main;index index.html index.php index.html;root/data/web/ Zabbix.lifec.com;location/{ try_files $uri $uri//index.php? $args;} Location ~ ^ (. +.php) (. *) $ { Fastcgi_split_path_info ^ (. +.php) (. *) $; Include fastcgi.conf; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param path_info $fastcgi _path_info;}}
Note: Configuration Tips
Nginx will be connected to the loopback address 9000 port execution PHP files, the use of TCP/IP protocol, the speed is relatively slow.
We recommend that you switch to using the socket connection: will fastcgi_pass 127.0.0.1:9000; change to Fastcgi_pass Unix:/var/run/phpfpm.sock;
10. Configuring Host Domain Access
[Email protected] ~]# echo "192.168.10.175 zabbix.lifec.com" >> vim/etc/hosts
11. Restart Nginx
[[Email protected] conf]# service Nginx restartstopping nginx: [ OK ]starting nginx: [ OK ]
12. Access Testing
Nginx page
PHP page
php5.5+nginx1.9