1. 安装Nginx:http://www.cnblogs.com/vurtne-lu/p/7010065.html
2. 编译安装
[root@zabbix opt]# wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror [root@zabbix opt]# mv mirror php-5.5.35.tar.gz [root@zabbix opt]# tar -zxvf php-5.5.35.tar.gz [root@zabbix opt]# cd php-5.5.35 [root@zabbix 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 --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --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 [root@zabbix php-5.5.35]# make && make install [root@zabbix php-5.5.35]# ln -s /usr/local/product/php-5.5.35 /usr/local/php [root@zabbix php-5.5.35]# cp php.ini-production /usr/local/php/etc/php.ini [root@zabbix php-5.5.35]# cd /usr/local/php/etc/ [root@zabbix php-5.5.35]# cp php-fpm.conf.default php-fpm.conf
3. 启动php-fpm
[root@zabbix etc]# /usr/local/product/php-5.5.35/sbin/php-fpm [root@zabbix etc]# netstat -tunlp tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 26086/php-fpm
4. 添加service管理,编写启动脚本:
[root@zabbix ~]# 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 5 # Default-Stop: 0 1 6 # Short-Description: starts php-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO prefix=/usr/local/php exec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpm php_fpm_CONF=${prefix}/etc/php-fpm.conf php_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID" wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; 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 is 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 is 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) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload|status}" exit 1 ;; esac
5. 添加启动权限
[root@zabbix ~]# chmod +x /etc/rc.d/init.d/php-fpm
6. 添加到chkconfig管理,设置随系统启动
[root@zabbix ~]# chkconfig --add php-fpm #php-fpm加入服务 [root@zabbix ~]# chkconfig php-fpm on #php-fpm 234级别下设置为启动 [root@zabbix ~]# chkconfig --list php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off # 查看php-fpm服务当前配置
7. service使用方法
[root@zabbix ~]# service php-fpm start # 启动 [root@zabbix ~]# service php-fpm stop # 关闭 [root@zabbix ~]# service php-fpm restart # 重启 [root@zabbix ~]# service php-fpm reload # 重载 [root@zabbix ~]# service php-fpm configtest #检查配置文件
8. 配置测试站点
[root@zabbix ~]# mkdir /data/web/zabbix.lifec.com -p [root@zabbix ~]# mkdir /data/logs/nginx/ -p [root@zabbix ~]# mkdir /data/logs/zabbix [root@zabbix ~]# vim /data/web/zabbix.lifec.com/info.php <?php phpinfo(); ?>
9. 配置nginx.conf配置文件
[root@zabbix conf]# cat nginx.conf user 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 65; #gzip on; include extra/*.conf; }
10. 编辑nginx虚拟主机
[root@zabbix conf]# pwd /usr/local/product/nginx-1.9.15/conf [root@zabbix conf]# mkdir extra [root@zabbix conf]# cd extra [root@zabbix conf]# vim nginx.conf server { listen 8027; server_name zabbix.lifec.com; access_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; } }
注:配置提示
nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢。
建议大家换成使用socket方式连接:将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/phpfpm.sock;
10. 配置主机域名访问
[root@zabbix ~]# echo "192.168.10.175 zabbix.lifec.com" >> vim /etc/hosts
11. 重启Nginx
[root@zabbix conf]# service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ]
12. 访问测试
Nginx页面
PHP页面