Setting up logging on LAMP Stack

Posted January 4, 2015 7.5k 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 :)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

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:

After spending the better part of the morning on this problem, here is what I learned…

  1. PHP error logging is off by default
  2. To enable it, you must edit the /etc/php/7.4/apache2/php.ini file
  3. Specifically, uncomment line 586 so that instead of “;error_log = php_errors.log” it reads “error_log = php_errors.log”
  4. Restart apache (“sudo systemctl restart apache2”)
  5. To test, introduce a PHP error in your functions.php file
  6. The error log will be in the root of your site in a file named php_errors.log
  7. To find this file in your droplet, use “sudo find / -name php_errors.log

If you want to put the error log file in a folder:

  1. Create a folder in your site (e.g. ”/site-root/logs") and then copy the php_errors.log file into it
  2. Edit the path in the php.ini file starting from the site root (e.g. “error_log = /logs/php_errors.log”)
  3. If you have multiple sites, you’ll have to create the folders in every site, so maybe it’s easier and more reliable to leave the log in the root.

Note: Newer droplets will probably come with higher versions of PHP. So instead of “7.4” substitute “8.0” or whatever you’ve got.