search

Home  >  Q&A  >  body text

php-nginx - Configure nginx + php + spwan-fcgi, error 502 Bad Gateway and php-fcgi cannot be started.

First I have configured nginx

Use the command service nginx start in Linux to start, and log in to localhost to see the welcome page.

Then modify the default file according to the online tutorial

During the modification process, I added index.php to the server,
root is still /usr/share/nginx/html, no changes have been made.

I changed /usr/share/nginx/html/index.html to index.php

When I open localhost, a 502 bad gateway error is reported.

Start php-fcgi and display child exited with: 127

According to what is said on the Internet, I have tested whether the cache is not enough or the threads are not enough. It should not be a problem with php-fpm. I'm wondering if it's because php-fcgi is not started?

黄舟黄舟2740 days ago667

reply all(4)I'll reply

  • 迷茫

    迷茫2017-05-16 17:25:13

    I’ll ask myself some questions and tell you my solution.
    The answer on the first floor is correct, but starting php-cgi didn't work on my machine for some reason, so I downloaded spwan-fcgi, which is a software for managing php-cgi.
    After successful installation, enter the command spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi (the bold words should be modified according to your location. ) after starting.
    I still don't know why php-fpm cannot start. . .

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 17:25:13

    php-cgi has not been started yet, it definitely won’t work. The solution is to start php-cgi

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 17:25:13

    PHP-FPM is an independent program that does not depend on PHP-CGI.
    The main process of PHP-FPM can manage its own work process, so spwan-fcgi is not needed.
    Installation method on Ubuntu/Debian:

    sudo apt-get install nginx php5-fpm php5-mysqlnd mysql-server
    服务管理:
    sudo /etc/init.d/nginx start|stop|restart
    sudo /etc/init.d/php5-fpm start|stop|restart
    sudo /etc/init.d/mysql start|stop|restart
    配置目录:
    Nginx:   /etc/nginx/
    PHP-FPM: /etc/php5/fpm
    

    For configuration methods, please refer to:
    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;
        }
    }
    

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:25:13

    PHP under nginx needs to use php-fpm. Add

    when compiling php.

    --enable-fpm

    ,
    Then you need to create the php-fpm configuration file php-fpm.conf in the etc directory of php (configuration reference: http://qiananhua.com/22#title-4)
    Then you can start php-fpm

    /usr/local/php/sbin/php-fpm -t

    reply
    0
  • Cancelreply