How do you set the PHP error log location in Apache conf file?
From: error_log per Virtual Host?
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/domains/example.com/html
ErrorLog /var/www/domains/example.com/apache.error.log
CustomLog /var/www/domains/example.com/apache.access.log common
php_flag log_errors on
php_flag display_errors on
php_value error_reporting 2147483647
php_value error_log /var/www/domains/example.com/php.error.log
</VirtualHost>
For those wishing to do this using php-fpm (which I meant to originally post about), here's how you do it:
Ensure you're logged in as root, or using sudo
for all your commands.
Go into your php-fpm directory*, using the command below:
cd /etc/php/fpm/
In that directory, edit your php.ini file and add the following to the end:
If you want to set error log by host
[HOST=www.example.com]
error_log=/var/www/myapplication/path/to/my/error.log
[HOST=sub.example.com]
error_log=/var/www/mysubapplication/path/to/my/error.log
If you want to set error log by path (handy if you're working on a server with an IP address but no domain)
[PATH=/var/www/myapplication]
error_log=/var/www/myapplication/path/to/my/error.log
[PATH=/var/www/mysubapplication]
error_log=/var/www/mysubapplication/path/to/my/error.log
You now need to go into the pool directory*, using the command below:
cd /etc/php/fpm/pool.d/
In that directory, edit the file www.conf. Note the values for user
and group
in that file, whose out-of-the-box setting is www-data
for both. Look for the term catch_workers_output
and make sure it is uncommented and set to yes
, like so:
catch_workers_output = yes
Now you need to create the error log file(s) and ensure that php-fpm has access to it. This is why you needed to note the values for user
and group
from the previous file edit. Create an error log file for each HOST/PATH you set when editing php.ini
and give them the appropriate permissions and ownership, for example:
touch /var/www/myapplication/path/to/my/error.log
chmod 0660 /var/www/myapplication/path/to/my/error.log
chown www-data:www-data /var/www/myapplication/path/to/my/error.log
Finally, restart your php-fpm service using the command** below:
service php-fpm restart
* Note: If, like me, you install declared versions of php-fpm, the directory paths will change to (for example) the following:
/etc/php/5.6/fpm/
/etc/php/5.6/fpm/pool.d/
/etc/php/7.1/fpm/
/etc/php/7.1/fpm/pool.d/
** The service takes a specific versioned name if you installed declared versions, and you will need use (for example) the following:
service php5.6-fpm restart
service php7.1-fpm restart
I config it like this,
/etc/apache2/envvars
# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
SUFFIX=
fi
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
/etc/apache2/sites-available/000-default.conf
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined