1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 在CentOs 5.1中使用rpm安装NGINX+php+mysql(二)

在CentOs 5.1中使用rpm安装NGINX+php+mysql(二)

时间:2022-04-27 04:40:33

相关推荐

在CentOs 5.1中使用rpm安装NGINX+php+mysql(二)

算是原创。转载请注明此地址,随着对NGINX认知的深入,此文会不定期更新或是修正。

以下兵分两路来说明:一是直接利用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 0

phpcgi="/usr/bin/php-cgi"

prog=$(basename ${phpcgi})

FCGIPORT="8888"

FCGIADDR="127.0.0.1"

FCGIUSER="apache"

FCGIGROUP="apache"

PHP_FCGI_CHILDREN=5

PHP_FCGI_MAX_REQUESTS=1000

export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS

[ -e /etc/sysconfig/php-cgi ] && . /etc/sysconfig/php-cgi

lockfile=/var/lock/subsys/php-cgi

start() {

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>&1

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

stop

start

}

force_reload() {

restart

}

fdr_status() {

status $prog

}

case "$1" in

start|stop|restart)

$1

;;

status)

fdr_status

;;

condrestart|try-restart)

[ ! -f $lockfile ] || restart

;;

*)

echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"

exit 2

esac

然后,开机自动运行:

[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-cgi

spawn-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 start

Starting nginx: [OK]

9、在IE栏里输入[url]http://124.207.102.22/index.htm[/url]这时NGINX已在正常运行。如下图:

在/usr/share/nginx/html下面新建index.php

<?php

phpinfo();

?>

在IE栏里输入[url]http://124.207.102.22/index.php[/url]这时NGINX已在正常运行。如下图:

10、那如何实现php的运行呢。在第7或第8步骤中,已开启了PHP的进程:

[root@nginx-freetds ~]# ps -aux |grep php

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ

nginx 25130.01.9177204964 ?Ss 20:45 0:00 /usr/bin/php-cgi

nginx 25140.00.617756 ?S20:45 0:00 /usr/bin/php-cgi

nginx 25150.00.617756 ?S20:45 0:00 /usr/bin/php-cgi

nginx 25160.00.617756 ?S20:45 0:00 /usr/bin/php-cgi

nginx 25170.00.617756 ?S20:45 0:00 /usr/bin/php-cgi

nginx 25180.00.617756 ?S20:45 0:00 /usr/bin/php-cgi

root25420.00.2 3892 676 pts/0R+ 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_name124.207.102.22aliasanother.alias;####域名

root /usr/share/nginx/html; ####路径

indexindex.php index.html index.htm;####index

location ~ \.php$

{

include fastcgi.conf;

fastcgi_pass 127.0.0.1:9000;

fastcgi_indexindex.php;

}

想多加虚机吗。呵呵,多来几个吧(日志选项请自位参考CONF文件自行研究)。

基本上完成了。有些功能还需要参考官方文档深入研究学习下

接下来,研究下rpm安装的情况下实现php连ms sql server.(tar包的已成功且在用啦)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。