今天需要搭建一个ngine+php的服务器环境,之前都是使用lamp的环境,因此在搭建的过程中遇到了很多问题,在此总结如下:
ngine本身不支持php,所以需要安装php-fpm的支持,怎样安装程序以及php拓展在这就不多说了,百度一下就会解决。
首先安装ngine,安装成功后打开ngine的配置文件,配置文件路径:/usr/local/ngine/conf/ngine.conf.
修改配置信息如下:
server {
listen80;
server_namelocalhost;
#charsetkoi8-r;
#access_loglogs/host.access.logmain;
location
/ {
roothtml;
indexindex.html
index.htm index.php;
}
#error_page404/404.html;
#
redirectserver error pages to the static page /50x.html
#
error_page500
502 503
504/50x.html;
location
= /50x.html {
roothtml;
}
#
proxy thePHP scripts to Apache listening on 127.0.0.1:80
#
#location
~\.php$ {
#proxy_passhttp://127.0.0.1;
#}
#
pass thePHP scripts to FastCGI server listening on
127.0.0.1:9000
#
location
~ \.php$ {
root/usr/local/nginx/html;
fastcgi_pass127.0.0.1:9000;
#fastcgi_pass
unix:/var/run/php5-fpm.sock;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
#
deny accessto .htaccess files, if Apache's document root
#
concurswith nginx's one
#
#location
~/\.ht {
#denyall;
#}
}
安装php环境,安装成功后打开php配置文件php.ini,将cgi.fix_pathinfo=0改成cgi.fix_pathinfo=1。
接下来就要安装php-fpm,安装成功后打开配置文件(/etc/php5/fpm/),把listen
=
/var/run/php5-fpm.sock改为
listen =127.0.0.1:9000。
到此环境就配置结束了,接下来就是将服务重新启动重启ngine以及php-fpm的进程,启动和关闭php5-fpm的进程命令如下:
sudo service php5-fpm
stop关闭
sudo service php5-fpm
start开启
sudo service php5-fpm
restart 重启
sudo service php5-fpm
status
备注:如果遇到浏览器提示:no input file
specified.,是因为,php.ini的cgi.fix_pathinfo=0,将0改成1解决;
如果遇到浏览器提示:File not
found是因为nginx的配置文件的路径错误,将fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;改成fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;即可。