We have an out-of-the-box PHP application running on a subdomain, and it's logging errors in its DocumentRoot:
/var/www/appname/path/to/document/root/php-errors.log
...instead of where we want the error logs to go:
/var/www/appname/logs/php-errors.log
Since I don't want to change the code in the out-of-the-box application, and I don't want to change the error log location for all the subdomains (read: file php.ini), how can I do this in just the Apache configuration file that relates to the subdomain?
The default error log differs from environment to environment, so it’s advisable to manually set the location of the file. Here’s how: Set the error_log entry to the desired path of the log file. For example, you might use error_log = /logs/php-errors.log.
There are two possible values for error_log: a custom log file and the syslog. If the syslog is used, then all PHP errors will be sent directly to the default system log file—in Linux, this is typically /var/log/syslog. The more manageable method is to use a custom log file.
If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.
In WHM 1 Log into WHM 2 Navigate to MultiPHP Manager 3 Find the domain you'd like to change the error log location for 4 Click the "Edit PHP-FPM" link 5 Change the log location in "The error log file (error_log)" relative to the folder "logs" within the user's home directory 6 Save your changes
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With