11

I get 504 gateway timeout when I try to reach my server.

A small check didn't find any logs on php5-fpm logs, but just to make sure, I tried to restart it.

When I am trying to restart it:

sudo service php5-fpm restart

I get [fail], but when I do

sudo service php5-fpm stop
sudo service php5-fpm start

I get no error.

How can I investigate it if there are no logs? What can I do?

6 Answers 6

19

Did you check your error_log file for php-fpm? Location of that file should be declared in your php-fpm.conf (in Ubuntu config is /etc/php5/fpm/php-fpm.conf, log file is /var/log/php5-fpm/log), also check your log_level, if is disabled (;log_level), please enable it and change it to the debug. After that try restart php5-fpm service and check your logs.

You can also try to run php5-fpm in foreground mode:

# php5-fpm -y /etc/php5/fpm/php-fpm.conf

Maybe this show you something interesting.

5
  • 2
    In my case, this command started php5-fpm whereas service php5-fpm start did not. Thanks! Jul 26, 2014 at 10:23
  • Davis, it seems to work for me +1! But.. jamzed gave me the solution, I found some error +1! thank you all! Jun 11, 2015 at 16:27
  • If you start FPM using an upstart job, then the php-fpm startup logs will be written to /var/log/upstart/ Jan 21, 2017 at 8:00
  • 1
    For php7.0 use php-fpm7.0 -F -c /etc/php/7.0/fpm/php-fpm.conf
    – Yadvendar
    Jun 8, 2017 at 16:24
  • php-fpm7.4 -F -c /etc/php/7.4/fpm/php-fpm.conf Jul 21, 2023 at 17:11
5

Standard troubleshooting procedure:

  • Check the log file. If you don't know where it is check the config or to figure out for certain find the pid with ps aux | grep php-fpm, then do lsof -p $PID | grep log (omit the grep if it shows nothing).
  • 99% of the time log files will show you the cause. If not, look for a logging level in the config, raise it and try again.
  • Perhaps it quits instantly and you can't get the PID to inspect the process. You can also try starting the process in the foreground, but this means figuring out which commandline switches you need to use. Usually you just need to point it at your existing config.
  • If neither the log file or stdout/stderr (foreground output) contain include any clues it's time for strace... but that's another post.
1
  • +1 nice way to find the log file! Jun 11, 2015 at 2:42
3

This note helped me: https://bugs.launchpad.net/nginx/+bug/1366651

In my case, updating to nginx > 1.6.1 the parameters that are passed to php5-fpm are located in fastcgi.conf instead of in fastcgi_params, resulting in a PHP that always returns 200 (ok), but never any content, because the SCRIPT_FILENAME was no longer set.

I hope it also helps someone else.

2

For me, the problem was my php-fpm.conf file was not using the default config filename - it was named /etc/php5/fpm/php5-fpm.conf ( php5-fpm.conf vs php-fpm.conf )

php5-fpm -t  

[26-Jul-2014 22:39:16] ERROR: failed to open configuration file '/etc/php5/fpm/php-fpm.conf': No such file or directory (2)
[26-Jul-2014 22:39:16] ERROR: failed to load configuration file '/etc/php5/fpm/php-fpm.conf'
[26-Jul-2014 22:39:16] ERROR: FPM initialization failed

I renamed the conf file to php-fpm.conf and that fixed the problem.

sudo mv /etc/php5/fpm/php5-fpm.conf /etc/php5/fpm/php-fpm.conf
sudo service php5-fpm restart
 * Restarting PHP5 FastCGI Process Manager php5-fpm                                                                           [ OK ]
0

I experienced this problem of no log files then noticed that I was accessing the URL over HTTPS instead of HTTP and that protocol had not been set up in Nginx so PHP5-FPM wasn't getting the traffic.

Might help someone.

0

It can happen that on an Ubuntu dist-upgrade the package php5-fpm is uninstalled because php 7 uses php-fpm instead. try running this on the console:

php5-fpm

If it doesn't exist you probably use php 7 already, so install

apt-get install php-fpm

which will install the php7 version

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .