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
to manage logs. Here are the steps to do so.
-
Open
/etc/php5/fpm/pool.d/www.conf
:$ sudo nano /etc/php5/fpm/pool.d/www.conf
-
Uncomment the following two lines by removing
;
at the beginning of the line:;php_admin_value[error_log] = /var/log/fpm-php.www.log ;php_admin_flag[log_errors] = on
-
Create
/var/log/fpm-php.www.log
:$ sudo touch /var/log/fpm-php.www.log;
-
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. -
Restart php5-fpm:
$ sudo service php5-fpm restart
Now your logs will be in /var/log/fpm-php.www.log
.
请发表评论