By default, Apache and PHP will log events in the same log file, which is either at /var/log/httpd/error.log or /var/log/apache2/error.log. It is not ideal to have both Apache and PHP log errors in the same log file. The following string of commands creates a directory to log PHP events and a log file just for PHP, so we can have log PHP events separate from the Apache events.
mkdir /var/log/php
chown root:apache /var/log/php or chown root:www-data /var/log/php
chmod 2750 /var/log/php
touch /var/log/php/error.log
chmod 0664 /var/log/php/error.log
Run restorecon to update the SELinux context.
restorecon -Rv /var/log/php
The ls -lZ /var/log/php command can be used to verify that error.log file has SELinux type httpd_log_t.
The ls -lZ /var/log | grep php command can be used to verify that the /var/log/php directory has SELinux type httpd_log_t.
Modify the php.ini to list the directory where the error.log is located.
Depending on the Linux distro being used, restart Apache or HTTPD.
service apache2 restart
service httpd restart
To verify that the PHP.ini file has updated to log errors to /var/log/php/error.log, load the phpinfo.php file in your Web browser. Search the phpinfo.php file for error_log, and verify the error_log is /var/log/php/error.log.
To test this to verify that PHP errors will be logged to /var/log/php/error.log instead of /var/log/httpd or /var/log/apache2, create a PHP file that includes a resource that does not exist. As an example, the following PHP includes bogus.php. There is no such file as bogus.php on the Web server. This should produce an error in the PHP log.
<?php
include 'bogus.php';
echo 'There is no such file as bogus.php on the Web server. Check the PHP error.log.';
?>
Use the tail command to view the PHP error.log.
tail /var/log/php/error.log