Setting up logging on LAMP Stack

January 4, 2015 2.6k views

Hello there -

I'm having a few issues I can't seem to sort out - I was hoping someone could point me in the right direction. I've googled and searched these forums to no avail.

I have a droplet set up with a nice little LAMP stack, phpMyAdmin, Fail2Ban, etc. I added SSL today, and am currently running through the joys of doing that (which I won't go into right now) - and found I needed Apache and PHP error logs. I had no problem setting up the directory/location of where to put the log files, and the apache logs seem to be working fine. However, the PHP log file I set up isn't doing anything. I even purposely made PHP mistakes to test that the log was working, and it's not. (I do see the PHP errors showing up in the apache log though - I'd rather keep them separated, if I can.)

I set up the PHP error log location in my php.ini file, and the phpinfo() test I have tells me that PHP is looking for the log where I placed it, however, nothing is getting written to the log file. So I'm wondering if I missed something along the line? (if it helps, I directed the log files to be placed in a /home/logs directory I created.)

And while I'm at it, I'd love to make the error logs just a bit more verbose. Is there any way to pull that off?

Thanks muchly :)

  • I believe the php.ini file only applies to the command line version of php, and not the apache php module. You can test this out by invoking php on the command line with a bad php script. The log file should show up where you invoked php, that is if you didn't supply a direct path in the php.ini file.
    Unfortunately, I don't know how to separate out the errors for any apache module. Sorry.

  • Need to clarify my previous comment. The php.ini log file option only applies to the command line version. The apache module logging controls goes with the apache config files. I have not found a way to redirect apache log files on a per-module basis. Only found verbosity settings for each module.

  • Thank you so much! I appreciate it :)

1 Answer

The php.ini for PHP processes started by Apache is located at file /etc/php5/apache2/php.ini You can also change PHP setting in an .htaccess file in the VitualHost's root directory using the syntax:

php_flag log_errors on
php_value error_reporting 32767
php_value error_log "/path/to/file"

The integer value 32767 corresponds to E_ALL (For more info on constants see here.)

For more info on the different log levels, check out:

Have another answer? Share your knowledge.