124

On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts with separate log files. We cannot seem to separate the php error_log between virtual hosts.

Overriding this setting in the <Location> of the httpd.conf does not seem to do anything.

Is there a way to have separate php error_logs for each Virtual Host?

Philip Raath
  • 460
  • 3
  • 18
Michael Stum
  • 177,530
  • 117
  • 400
  • 535

11 Answers11

147

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

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

tirenweb
  • 30,963
  • 73
  • 183
  • 303
Clutch
  • 7,404
  • 11
  • 45
  • 56
  • 10
    Depending on your config, you may need to manually create the log file and set the owner/group to the same user/group that Apache is using. Apache won't warn you if it can't write to the log file. – Ian Dunn Jun 24 '11 at 23:41
  • Note that the "error_reporting" value changes with new versions of PHP as they add more error levels. E_ALL = "30719" right now. – ReactiveRaven Mar 08 '12 at 16:26
  • 2
    Since "error_reporting" values keep changing and since you can't use PHP constants like "E_ALL" and "E_STRICT" outside of php, this is how you ensure you always have ALL errors logged: php_value error_reporting 2147483647 – Buttle Butkus Jun 10 '12 at 21:44
  • Why would you want your log in your public domain space? – AlxVallejo Jul 30 '14 at 22:28
  • 1
    The log file wouldn't be public. /html/ is the public space. – Clutch Sep 10 '14 at 19:40
89

To set the Apache (not the PHP) log, the easiest way to do this would be to do:

<VirtualHost IP:Port>
   # Stuff,
   # More Stuff,
   ErrorLog /path/where/you/want/the/error.log
</VirtualHost>

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

Apache Error Log Page

demonkoryu
  • 1,247
  • 10
  • 27
helloandre
  • 10,541
  • 8
  • 47
  • 64
15

I usually just specify this in an .htaccess file or the vhost.conf on the domain I'm working on. Add this to one of these files:

php_admin_value error_log "/var/www/vhosts/example.com/error_log"
7ochem
  • 2,183
  • 1
  • 34
  • 42
Kevin
  • 13,044
  • 11
  • 55
  • 76
  • 1
    Can anyone comment on the difference between `php_admin_value` and `php_value`? – Nick M Jul 04 '14 at 01:31
  • 1
    This explains the difference: http://mattiasgeniar.be/2012/02/18/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/ – Jeremy Jul 08 '14 at 16:30
  • @Jeremy That page no longer exists. Sorry. this post is really old. – tmarois Oct 11 '20 at 15:20
  • 1
    @tmarois Updated link: https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/ – Jeremy Oct 13 '20 at 18:16
9

The default behaviour for error_log() is 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.

Tanjim Ahmed Khan
  • 650
  • 1
  • 9
  • 21
Mat
  • 6,694
  • 7
  • 35
  • 39
  • 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 Aug 01 '08 at 22:31
7

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

Sandesh
  • 1,190
  • 3
  • 23
  • 41
rkulla
  • 2,494
  • 1
  • 18
  • 16
7

Try adding the php_value error_log '/path/to/php_error_log to your VirtualHost configuration.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hoyhoy
  • 6,281
  • 7
  • 38
  • 36
6
php_value error_log "/var/log/httpd/vhost_php_error_log"

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

or Apache will write the log to the its error_log.

akash
  • 22,664
  • 11
  • 59
  • 87
5

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.

akash
  • 22,664
  • 11
  • 59
  • 87
James Hartig
  • 1,009
  • 1
  • 9
  • 20
4

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

<VirtualHost myvhost:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /opt/web
    ServerName myvhost
    ErrorLog logs/myvhost-error_log
    CustomLog logs/myvhost-access_log common
</VirtualHost>
ejunker
  • 10,816
  • 11
  • 41
  • 41
3

You can try:

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

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

Tanjim Ahmed Khan
  • 650
  • 1
  • 9
  • 21
2

Create Simple VirtualHost:

example hostname:- thecontrolist.localhost

  1. C:\Windows\System32\drivers\etc

    127.0.0.1 thecontrolist.localhost in hosts file

  2. C:\xampp\apache\conf\extra\httpd-vhosts.conf

    <VirtualHost *>
      ServerName thecontrolist.localhost
      ServerAlias thecontrolist.localhost
      DocumentRoot "/xampp/htdocs/thecontrolist"
      <Directory "/xampp/htdocs/thecontrolist">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
      </Directory>
    </VirtualHost>
    
  3. Don't Forget to restart Your apache. for more check this link

oguz ismail
  • 1
  • 16
  • 47
  • 69
Parveen Chauhan
  • 1,396
  • 12
  • 25