问题描述
首先我已经配置好了nginx在linux里面使用命令 service nginx start,可以启动,并且登陆localhost可以看到欢迎页面。
然后按照网上的教程修改default文件在修改过程中,我在server中添加了index.php,root 还是 /usr/share/nginx/html,没有做改变。
我将/usr/share/nginx/html/index.html 修改成了index.php当我打开localhost的时候 报502 bad gateway的错误。
启动php-fcgi,显示child exited with: 127按照网上的说法,什么缓存不够,线程不够,我都实验过了。应该不是php-fpm的问题。我在想是不是因为php-fcgi没有启动的原因?
问题解答
回答1:我自问自答一下,说说我的解决办法。一楼的答案说的没错,但是启动php-cgi不知道为什么在我的机器上一直不行,于是我下载了spwan-fcgi,是一款管理php-cgi的软件。安装成功后,输入命令spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi(其中粗体字要根据自己的位置来修改。)启动之后就可以了。我现在也不知道为什么php-fpm无法启动。。。
回答2:php-cgi都没启动,肯定不行,解决方法就是启动php-cgi
回答3:PHP-FPM是独立运行的程序,不依赖PHP-CGI.PHP-FPM主进程就能管理自己的工作进程,所以也不需要spwan-fcgi.Ubuntu/Debian上的安装方法:
sudo apt-get install nginx php5-fpm php5-mysqlnd mysql-server服务管理:sudo /etc/init.d/nginx start|stop|restartsudo /etc/init.d/php5-fpm start|stop|restartsudo /etc/init.d/mysql start|stop|restart配置目录:Nginx: /etc/nginx/PHP-FPM: /etc/php5/fpm
配置方法可以参考:http://huoding.com/2013/10/23/290
server { listen 80; server_name foo.com; root /path; index index.html index.htm index.php; location / {try_files $uri $uri/ /index.php$is_args$args; } location ~ .php$ {try_files $uri =404;include fastcgi.conf;fastcgi_pass 127.0.0.1:9000; }}回答4:
nginx下php需要使用php-fpm 在编译php的时候加上
--enable-fpm
,然后需要在php的etc目录下建立php-fpm的配置文件php-fpm.conf(配置参考:http://qiananhua.com/22#title-4)接着就可以启动php-fpm
/usr/local/php/sbin/php-fpm -t