nginx结合php,配置如下:
Configure Nginx to execute PHP script. This example shows to use PHP-FPM ( PHP FastCGI Process Manager ). |
安装php & php-fpm
# yum –enablerepo=epel -y install php php-mbstring php-pear php-fpm 配置php-fpm # vim /etc/php-fpm.d/www.conf # 39 行 user = ngnx; apache change nginx; # 41 行 group = nginx; # /etc/rc.d/init.d/php-fpm start Starting php-fpm: [ OK ] # chkconfig php-fpm on 配置nginx支持php # vim /etc/nginx/conf.d/default.conf 在 server 部分中添加
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; }
注意:这个有的时候会识别不出来$document_root,改成网站的根目录就可以了;
# /etc/rc.d/init.d/nginx restart Stopping nginx: [ OK ]
Starting nginx: [ OK ] 创建一个php.info的脚本,测试一下是否配置成功; # echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php 访问地址是:http://www.iopenstack.com/info.php