0
votes

On a Ubuntu web server [LAMP], I'm trying to get PHP errors to write into a php_error file, but no matter what I do, they keep going to the apache log.

Here's what I have tried/done:

  1. Edited the php.ini file:

    • error_reporting = E_ALL | E_STRICT
    • display_error = Off
    • log_errors = On
    • error_log = /var/log/php_errors.log
  2. Restarted Apache

  3. Checked the phpinfo() output to verify that the changes I made to the php.ini file took -- they did.

  4. After verifying that the errors were still going to the Apache log, I physically created the php_errors.log and tried again. Still going to the Apache log!

  5. Rebooted the web server! Still...!

Anybody have a solution?

3
check log_errors_max_len is greater than 0DevlshOne
And does the web server have permission to create /var/log/php_errors.log? You may need to place that inside a location Apache can write to like /var/log/httpd/php_errors.log or /var/log/apache2/php_errors.logMichael Berkowski

3 Answers

2
votes

Check the directory permissions for /var/log. Ensure that the user your Web service is running as has write permissions to that folder. Alternatively, create a subfolder (/var/log/phplogs?) and assign explicit permissions on that for the user in question then change the error_log value to be a file in that folder

2
votes

It had to do with ownership. One or the other has worked [for reasons that are not clear to me]:

chown www-data:www-data /var/log/php_error.log

chown same-user-as-www-home:same-user-as-web-home /var/log/php_error.log

Also, the following has made a difference:

chmod 664 /var/log/php_error.log

[as opposed to chmod 644...again for reasons that are not clear to me]

0
votes

For the record, Ubuntu uses AppArmor and it limits what Apache does.

Additionally, to change the permissions to the file and editing the php.ini file, you must do the next steps:

Go to the next file

/etc/apparmor.d/abstractions

Edit this file

apache2-common

Add the next line

/var/log/php_errors.log rw,

where rw means the process could read and write this file

or you could also do:

sudo nano /etc/apparmor.d/abstractions/apache2-common

And finally, reload the configuration of apparmor

systemctl reload  apparmor

Note: Centos/Redhat/Oracle Linux uses SELinux and it requires the same step but the configuration is different.