PHP-FPM doesn't write to error log

前端 未结 11 1024
予麋鹿
予麋鹿 2020-11-27 09:12

I\'ve just installed a nginx+php-fpm server. Everything seems fine except that PHP-FPM never writes error to its log.

fpm.conf

[default]
listen = /va         


        
相关标签:
11条回答
  • 2020-11-27 10:04

    I had a similar issue and had to do the following to the pool.d/www.conf file

    php_admin_value[error_log] = /var/log/fpm-php.www.log
    php_admin_flag[log_errors] = on
    

    It still wasn't writing the log file so I actually had to create it by touch /var/log/fpm-php.www.log then setting the correct owner sudo chown www-data:www-data /var/log/fpm-php.www.log.

    Once this was done, and php5-fpm restarted, logging was resumed.

    0 讨论(0)
  • 2020-11-27 10:06

    I struggled with this for a long time before finding my php-fpm logs were being written to /var/log/upstart/php5-fpm.log. It appears to be a bug between how upstart and php-fpm interact. See more here: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1319595

    0 讨论(0)
  • 2020-11-27 10:10

    I gathered insights from a bunch of answers here and I present a comprehensive solution:

    So, if you setup nginx with php5-fpm and log a message using error_log() you can see it in /var/log/nginx/error.log by default.

    A problem can arise if you want to log a lot of data (say an array) using error_log(print_r($myArr, true));. If an array is large enough, it seems that nginx will truncate your log entry.

    To get around this you can configure fpm (php.net fpm config) to manage logs. Here are the steps to do so.

    1. Open /etc/php5/fpm/pool.d/www.conf:

      $ sudo nano /etc/php5/fpm/pool.d/www.conf

    2. Uncomment the following two lines by removing ; at the beginning of the line: (error_log is defined here: php.net)

      ;php_admin_value[error_log] = /var/log/fpm-php.www.log ;php_admin_flag[log_errors] = on

    3. Create /var/log/fpm-php.www.log:

      $ sudo touch /var/log/fpm-php.www.log;

    4. Change ownership of /var/log/fpm-php.www.log so that php5-fpm can edit it:

      $ sudo chown vagrant /var/log/fpm-php.www.log

      Note: vagrant is the user that I need to give ownership to. You can see what user this should be for you by running $ ps aux | grep php.*www and looking at first column.

    5. Restart php5-fpm:

      $ sudo service php5-fpm restart

    Now your logs will be in /var/log/fpm-php.www.log.

    0 讨论(0)
  • 2020-11-27 10:12

    There are multiple php config files, but THIS is the one you need to edit:

    /etc/php(version)?/fpm/pool.d/www.conf
    

    uncomment the line that says:

    catch_workers_output
    

    That will allow PHPs stderr to go to php-fpm's error log instead of /dev/null.

    0 讨论(0)
  • 2020-11-27 10:18

    In your fpm.conf file you haven't set 2 variable which are only for error logging.

    The variables are error_log (file path of your error log file) and log_level (error logging level).

    ; Error log file
    ; Note: the default prefix is /usr/local/php/var
    ; Default Value: log/php-fpm.log
    
    error_log = log/php-fpm.log
    
    ; Log level
    ; Possible Values: alert, error, warning, notice, debug
    ; Default Value: notice
    
    log_level = notice
    
    0 讨论(0)
提交回复
热议问题