3

Seems like I can't get error logging working on my server, I've set up my vhosts like in this description like suggested here.

<VirtualHost *:80>
   ServerAdmin admin@server.com
   DocumentRoot /var/www/html
   ServerName www.server.com
   ServerAlias server.com
   LogFormat combined
   ErrorLog /var/log/apache2/server.com-error_log
   TransferLog /var/log/apache2/server.com-access_log
   php_flag log_errors on
   php_flag display_errors off
   php_value error_reporting 6143
   php_value error_log /var/log/apache2/server.com-php-error.log
   ...
</VirtualHost>

access and error log are written correctly, the php error log file is created and has the same permission as the other two log files.

I also tried to set the logging in the php.ini, .htaccess file and in the script, all according to this guide.

php -v
 PHP 5.2.10-2ubuntu6.10 with Suhosin-Patch 0.9.7 (cli) (built: May  2 2011 23:24:44) 
 Copyright (c) 1997-2009 The PHP Group
 Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

Are there any other places I could check? The vHost configuration worked flawlessly on other servers.

Community
  • 1
  • 1
Rene Koller
  • 375
  • 1
  • 6
  • 15
  • What is your question? You say the log is created and everything, it would have the same permissions since it is created by the same user in the log dir. What is actually wrong? And what are you trying to check? – Sammaye Sep 24 '12 at 13:36
  • so have you tried accessing a page with a PHP error on it? – dnagirl Sep 24 '12 at 13:38
  • the error-log and access-log are created but not the server.com-php-error.log, nothing gets written into that file. – Rene Koller Sep 24 '12 at 13:39
  • As @dnagirl says have you done anything that requests a log to be written? – Sammaye Sep 24 '12 at 13:39
  • yes I've a page with an error, also it should log any `error_log()` in that file too? – Rene Koller Sep 24 '12 at 13:40
  • I think this is something isolated to your server rather than the config code you have displayed here – Sammaye Sep 24 '12 at 13:44
  • Make sure that those php_value values aren't being overridden somewhere farther down the httpd.conf chain - there can be many other .conf-type files included later on. If your settings, as shown above, were in effect, they'd show in `phpinfo()` output. Check that to see what's really in effect. – Marc B Sep 24 '12 at 14:19

3 Answers3

1

Probably it's due to permissions on /var/log/apache2. Take into account that PHP is running as an apache module, so it is running as the www-data user (in ubuntu at least). So you need that this user has at least execute permission on /var/log/apache2 and write permission on the log files, or better yet, execute and write permission on /var/log/apache2 (to be able to create new log files if needed).

So you can save the php log to another folder, or make it writable by the www-data user (in the latter case, you may also edit the /etc/logrotate.d/apache2 file so new logfiles after rotation get owned by the www-data user.

Carlos Campderrós
  • 22,354
  • 11
  • 51
  • 57
  • As you say, the log is written with Apache's permissions - if it was a permission error, then apache wouldn't be able to open its own standard logs and kill itself with a startup fatal error. – Marc B Sep 24 '12 at 14:18
  • @MarcB you're wrong, because apache starts as the `root` user, logs the requests to that folder and then it downgrades privileges to the `www-data` user. – Carlos Campderrós Sep 24 '12 at 14:28
  • Yes, but the php module will also be running as root at the time the log files are opened. the relinquishing of root privs is only done AFTER all startup activities are finished. – Marc B Sep 24 '12 at 14:30
  • @MarcB but the php logger does not log the requests, it does log the error, which happen after the downgrading of privileges, because the php parser/interpreter is not run as root – Carlos Campderrós Sep 24 '12 at 14:32
  • so? the php module stays alive within Apache for the lifetime of Apache, and keeps the error log open, even after the privs drop. The log is not continually opened/written/closed every time. – Marc B Sep 24 '12 at 14:34
  • Apache apparently has the permissions to write in that folder because the access and normal error log are working correctly. – Rene Koller Sep 25 '12 at 08:04
1

Type into your php script:

error_reporting(E_ALL);
ini_set('display_errors', true);

Than you get your errors and warnings printed

zeyorama
  • 444
  • 3
  • 12
  • displaying errors in the browser works but that doesn't help debugging backend php. I think everyone would agree that there should be a log file, displaying in the browser is only a temporary solution. – Rene Koller Sep 25 '12 at 08:08
  • For debugging in development okay, in production is this a bad solution right. /etc/log/httpd/error_log could help maybe – zeyorama Sep 25 '12 at 09:37
0

Try the default location for PHP log: /var/log/php.log

Zvonko Biskup
  • 393
  • 2
  • 9