1

I am trying to install nginx and php-fpm following this guide on a FreeBSD 11.1 system on a raspberrypi-B+.

Everything behaves as described in the guide up to point 14, which involves opening a php file with information about the system by running

phpinfo();

At this point, when I open http://localhost/info.php, nginx times out while waiting for an answer from php-fpm. The following message appears in the nginx log:

[error] 876#100128: *1 upstream timed out (60: Operation timed out) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

In /usr/local/etc/nginx/nginx.conf I have a section for php files:

location ~ \.php$ {
    root           /usr/local/www/nginx;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_read_timeout 180;
    fastcgi_param  SCRIPT_FILENAME $request_filename;    
    include        fastcgi_params;
}

and in /usr/local/etc/php-fpm.d/www.conf I have the line:

listen = 127.0.0.1:9000

So I checked if nginx can connect to php-fpm:

$ sudo sockstat -4 -6| grep nginx

gives

www      nginx      876   3  tcp4   127.0.0.1:80          127.0.0.1:35165
www      nginx      876   6  tcp4   *:80                  *:*
www      nginx      876   9  tcp4   127.0.0.1:60676       127.0.0.1:9000
root     nginx      875   6  tcp4   *:80                  *:*

where you can see the incoming connection requesting the page and the outgoing connection to port 9000 (fastcgi).

Looking at php-fpm with

$ sudo  sockstat -4 -6| grep php-fpm

gives

www      php-fpm    935   0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    934   0  tcp4   127.0.0.1:9000        *:*
www      php-fpm    934   4  tcp4   127.0.0.1:9000        127.0.0.1:60676
root     php-fpm    933   8  tcp4   127.0.0.1:9000        *:*

where you can see the incoming connection.

So nginx seems to be connected to php-fpm but nothing happens. In htop I can see a master process php-fpm with two worker child processes, one of which is taking almost 100% of the CPU time. After a while nginx times out and the worker php-fpm stays at 100% and does not release the socket. The php-fpm log file (/var/log/php-fpm.log) does not show any error:

[24-Dec-2017 23:09:21] NOTICE: fpm is running, pid 933
[24-Dec-2017 23:09:21] NOTICE: ready to handle connections

Pid 933 is the master. No log output from the child processes.

So this is what I have found and I do not have any idea of what I should look at next. Do you have any suggestions?

EDIT

The problem seems to be related to PHP-7.1. I have installed an older version (PHP-5.6) and the problem disappeared. I leave the question open in case the problem is related to some PHP-7 specific configuration.

8
  • Please post your PHP-FPM configuration file, just the parts that define the listener. Check if it's listening on port 9000 or on a Unix socket - you want the former to match your Nginx configuration.
    – Tim
    Dec 25, 2017 at 1:13
  • Even if you have php-fpm running, you need to have the nginx config to sent php scripts to port 9000. Do you have this? Something like: location ~\.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(.*)$; if (-f $request_filename) { fastcgi_pass 127.0.0.1:9000; }
    – Gmck
    Dec 25, 2017 at 4:27
  • @Gmck: Thanks for the hints. I have added the relevant parts from the configuration files to the question. Also, the output of sockstat seems to confirm that the two processes can connect, so I suppose the problem is somewhere else, but I may be wrong.
    – Giorgio
    Dec 25, 2017 at 10:08
  • @Tim: I have edited the question.
    – Giorgio
    Dec 25, 2017 at 10:08
  • If your PHP-FPM worker process is using 100% CPU, then there is something wrong with its settings or the actual software. It seems that it receives the request, but then something happens that makes it enter a busy loop and never return an answer. Dec 25, 2017 at 11:42

0

You must log in to answer this question.

Browse other questions tagged .