以下兵分两路来说明:一是直接利用php-cgi的FastCGI运行方式;二是利用Lighttpd的spawn-fcgi来控制进程的运行方法。先说说利用php-cgi的FASTCGI运行方式:7、创建php-cgi启动脚本,[root@nginx-freetds ~]# vi /etc/init.d/phpcgi#!/bin/sh## php-cgi - this script starts and stops the php-cgi daemin## chkconfig: - 85 15# description: Fast CGI php# processname: php-cgi# config: /etc/php.ini# pidfile: /var/run/php-cgi.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0phpcgi="/usr/bin/php-cgi"prog=$(basename ${phpcgi})FCGIPORT="8888"FCGIADDR="127.0.0.1"FCGIUSER="apache"FCGIGROUP="apache"PHP_FCGI_CHILDREN=5PHP_FCGI_MAX_REQUESTS=1000export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS[ -e /etc/sysconfig/php-cgi ] && . /etc/sysconfig/php-cgilockfile=/var/lock/subsys/php-cgistart() {echo -n $"Starting $prog: "/usr/bin/spawn-fcgi -a $FCGIADDR -p $FCGIPORT -C $PHP_FCGI_CHILDREN -u $FCGIUSER -g $FCGIGROUP -P /var/run/php-cgi.pid -f "${phpcgi}" >> /dev/null 2>&1retval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {stopstart}force_reload() {restart}fdr_status() {status $prog}case "$1" instart|stop|restart)$1;;status)fdr_status;;condrestart|try-restart)[ ! -f $lockfile ] || restart;;*)echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"exit 2esac然后,开机自动运行:[root@nginx-freetds ~]#/sbin/chmod +x /etc/init.d/phpcgi[root@nginx-freetds ~]#/sbin/chkconfig --add phpcgi[root@nginx-freetds ~]#/sbin/chkconfig --level 35 phpcgi on[root@nginx-freetds ~]#/sbin/chkconfig --level 35 nginx on但从网上说会遇到两个问题,这里摘录一位的解决方案。(我没有遇到。也没有机会测试下面的解决方式是否正确)[root@nginx-freetds ~]# cat /var/log/audit/audit.log| audit2allow -M local[root@nginx-freetds ~]#/usr/sbin/semodule -i local.pp下面说说利用Lighttpd的spawn-fcgi来控制进程的运行的方法:8、开启nginx及利用Lighttpd的spawn-fcgi来控制进程的运行[root@nginx-freetds ~]# spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nginx -g nginx -f /usr/bin/php-cgispawn-fcgi.c.187: child spawned successfully: PID: 2513参数含义如下
-f <fcgiapp> 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a <addr> 绑定到地址addr
-p <port> 绑定到端口port
-s <path> 绑定到unix socket的路径path
-C <childs> 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
-P <path> 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等因为,安装rpm 安装nginx时。会创建nginx用户和组。[root@nginx-freetds ~]# service nginx startStarting nginx: [ OK ]9、在IE栏里输入[url]http://124.207.102.22/index.htm[/url]这时NGINX已在正常运行。如下图:在/usr/share/nginx/html下面新建index.php<?phpphpinfo();?> 在IE栏里输入[url]http://124.207.102.22/index.php[/url]这时NGINX已在正常运行。如下图:10、那如何实现php的运行呢。在第7或第8步骤中,已开启了PHP的进程:[root@nginx-freetds ~]# ps -aux |grep phpWarning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQnginx 2513 0.0 1.9 17720 4964 ? Ss 20:45 0:00 /usr/bin/php-cginginx 2514 0.0 0.6 17720 1656 ? S 20:45 0:00 /usr/bin/php-cginginx 2515 0.0 0.6 17720 1656 ? S 20:45 0:00 /usr/bin/php-cginginx 2516 0.0 0.6 17720 1656 ? S 20:45 0:00 /usr/bin/php-cginginx 2517 0.0 0.6 17720 1656 ? S 20:45 0:00 /usr/bin/php-cginginx 2518 0.0 0.6 17720 1656 ? S 20:45 0:00 /usr/bin/php-cgiroot 2542 0.0 0.2 3892 676 pts/0 R+ 20:48 0:00 grep php可以看到,有五个进程正在运行。 默认情况下。NGINX是可以开启静态页面,但如何开启PHP。还是要在/etc/nginx/nginx.php设置的。
各位可以参考我的配置前后的截图(呵呵,研究下,有些参数是可以改变的。要举一返三吧):修改前:修改后:保存更改。然后service nginx restart便可了。11、配置虚拟主机
在APACHE上配置虚拟主机。想来各位都有一定的体验。那如何在NGINX中实现呢?[root@nginx-freetds html]# vi /etc/nginx/nginx.conf参考下图(开启https的样例也在内)。最后几行: server { listen 8000; ####监听端口 server_name 124.207.102.22 alias another.alias;####域名 root /usr/share/nginx/html; ####路径 index index.php index.html index.htm; ####index location ~ \.php$ { include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }想多加虚机吗。呵呵,多来几个吧(日志选项请自位参考CONF文件自行研究)。
基本上完成了。有些功能还需要参考官方文档深入研究学习下
接下来,研究下rpm安装的情况下实现php连ms sql server.(tar包的已成功且在用啦)
本文转自 rickyfang 51CTO博客,原文链接:http://blog.51cto.com/rickyfang/125841,如需转载请自行联系原作者