9

When accessing some PHP scripts on my website, I'm getting the dreaded 500 error message. I'd like to know what's wrong to fix it, but Nginx isn't logging any PHP errors in the log file I have specified. This is my server block:

server {
    listen 80;
    server_name localhost;
    access_log /home/whitey/sites/localhost/logs/access.log;
    error_log /home/whitey/sites/localhost/logs/error.log error;
    root /home/whitey/sites/localhost/htdocs;
    index index.html index.php /index.php;

    location / { 

    }

    location ~ \.php$ {
        fastcgi_pass unix:/tmp/phpfpm.sock;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires max;
    }
}

Note that some PHP scripts work fine, and others don't. So there isn't a global problem with PHP, there's just something in these scripts that's causing Nginx to throw the 500 error.

How can I get to the bottom of this? The only thing in error.log is an error about favicon.ico not being found.

4

7 Answers 7

9

You have to add the following to your php-fpm pool configurations:

catch_workers_output = 1

You have to add this line to each defined pool!

1
  • 2
    trying to get more info on php-fpm issue resulting in error 500 for php-fpm and nginx. In xlaravel.pool.conf I have catch_workers_output = yes. So no no 1. Which one is correct here?
    – rhand
    Jan 31, 2019 at 0:57
5

I had a similar issue.

I tried deploy phpMyAdmin with php-fpm 7.0 and nginx on CentOS7. Nginx showed me 500.html but there was not errors in any log file. I did all of this

catch_workers_output = 1

and

display_errors = On

Either nginx log or php-fpm log did not contained any error string.

And when I commented this line in nginx.conf I was able to see in browser page things that was wrong.

#    error_page 500 502 503 504 /50x.html;
#    location = /50x.html {
#    }

That was what helped me understand troubles.

3

php-fpm throws everything in /var/log/php5-fpm.log or similar.

6
  • 1
    That log just shows this: [13-Aug-2012 20:15:54] NOTICE: fpm is running, pid 10599 [13-Aug-2012 20:15:54] NOTICE: ready to handle connections [13-Aug-2012 20:18:37] NOTICE: Finishing ... [13-Aug-2012 20:18:37] NOTICE: exiting, bye-bye! [13-Aug-2012 20:18:39] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful Aug 13, 2012 at 18:39
  • Try to set `error_log to something. As php-fpm with nginx doesn't work as it works with apache2.
    – erickzetta
    Aug 13, 2012 at 18:41
  • The PHP-FPM log is just about errors of PHP-FPM. You can enable PHP logging seperately in your php.ini Aug 13, 2012 at 18:41
  • 1
    Or check stackoverflow.com/questions/8677493/…
    – erickzetta
    Aug 13, 2012 at 18:43
  • /var/log/php-fpm/www-error.log in my case. Nov 7, 2018 at 5:13
0

Look in your nginx.conf for an error_log definition. Maybe nginx writes something in this error log.

You might also enable logging to file on PHP.

1
  • I looked in the file that error_log is set to, and it's empty. No errors at all. Aug 13, 2012 at 18:39
0

For me, this seemed to be a problem with upstart, which was routing the logs for php-fpm to it's own custom location, e.g.:

/var/log/upstart/php5-fpm.log

There's also some bugginess with ubuntu Precise, 12.04 that may contribute to the lack of logging ability: https://bugs.php.net/bug.php?id=61045 If you're still running that version.

0

When PHP display_errors are disabled, PHP errors can return Nginx 500 error.

You should take a look to your php-fpm logs, i'm sure you'll find the error there. With CentOS 7 :

tail -f /var/log/php-fpm/www-error.log

You can also show PHP errors. In your php.ini, change :

display_errors = Off

to :

display_errors = On

Hope it helps.

-1

This is what happened to me:

When I deleted my error log, nginx noticed that it was no longer missing. When I recreated this file nginx would no longer recognise that it existed, therefore not writing to the file.

To fix this, run these commands (I'm on Ubuntu 14.04 LTS):

sudo service nginx reload

If that doesn't work, then try:

sudo service nginx restart
4
  • That is so completely not how nginx logging, or Unix file handling, works...
    – womble
    Aug 12, 2015 at 7:53
  • It fixed it for me, so I'm not complaining
    – Daniel
    Aug 12, 2015 at 8:16
  • 1
    Future reference: what probably happened was your directory was not owned by nginx so it could not create the log file after you deleted it. chown the parent dir. sudo chown -R www-data:www-data /var/log/nginx should've sorted it.
    – Edward
    Jun 27, 2017 at 9:59
  • This fixed my exact issue. I assume its pretty rare for people to delete their error log but I did. Thanks for the help
    – hendr1x
    Jan 18, 2022 at 2:26

You must log in to answer this question.

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