On one Linux Server running Apache and PHP 5, we got multiple Virtual Hosts with separate logfiles and everything. The only thing we cannot seem to separate between virtual hosts is the php error_log. Overriding this setting in the <Location> of the httpd.conf does not seem to do anything.

Did I overlook something? Is there a way to have separate php error_logs for each Virtual Host?

+14  A: 

You may already be doing this, but I would think the easiest way to do this would be to do:

<VirtualHost IP:IP>
More Stuff,
ErrorLog /path/where/you/want/it.log

If there is no leading "/" it is assumed to be relative.

Apache Error Log Page


That's the Apache error log, is it? PHP has it's own Error_Log specified in php.ini and does not seem to use Apache's error log?

Michael Stum
+2  A: 

The default behaviour is for error_log() to output to the Apache error log. If this isn't happening check your php.ini settings for the error_log directive - leave it unset to use the Apache log file for the current vhost.


I will check. I just wonder if it is possible to still have apache and php error log separate when we want to give developers a chance to debug their code without giving them the apache error log which might contain other sensitive data.

Michael Stum
+2  A: 

I usually just specify this in an .htaccess file or the vhost.conf on the domain I'm working on:

php_admin_value error_log "/var/www/vhosts/example.com/error_log"

+1  A: 

My Apache had something like this in httpd.conf. Just change the ErrorLog and CustomLog settings

<VirtualHost myvhost:80>
ServerAdmin [email protected]
DocumentRoot /opt/web
ServerName myvhost
ErrorLog logs/myvhost-error_log
CustomLog logs/myvhost-access_log common

Have you tried adding the php_value error_log '/path/to/php_error_log to your VirtualHost configuration?


You could try:

    <VirtualHost myvhost:80>
    php_value error_log "/var/log/httpd/vhost_php_error_log"
    </Virtual Host>

But i'm not sure if is going to work. I tried on my sites with no success.


yes, you can try php_value error_log "/var/log/php_log" in .htaccess or you can have users use ini_set() in the beginning of their scripts if they want to have logging

Another option, would be to enable scripts to default to the php.ini in the folder with the script, then go to the user/host's root folder, then to the server's root, or something similar. This would allow hosts to add their own php.ini values and their own error_log locations.

James Hartig

php_value error_log "/var/log/httpd/vhost_php_error_log"

It works for me, but I have to chage the permission of the log file.

Or Apache will write the log to the its error_log.


Don't set error_log to where your syslog stuff goes, eg /var/log/apache2, because they errors will get intercepted by ErrorLog. Instead, create a subdir in your project folder for logs and do php_value error_log "/path/to/project/logs". This goes for both .htaccess files and vhosts. Also make sure you put php_flag log_errors on

+2  A: 

If somebody comes looking it should look like this:

<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 6143
    php_value error_log /var/www/domains/example.com/php.error.log

This is for development only since display_error is turned on. You will notice that the apache error log is separate from the php error log. The good stuff is in php.error.log. Take a look here for the error_reporting key http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting