A+ Computing
Professional Web Design

How To Turn On PHP Error Logging

November 9th, 2021

Home > Articles > How To Turn On PHP Error Logging

Sometimes, when there is a problem with a web page, you may check the access and error logs as these can be good sources of information. You may not see the information you're looking for in those logs, though. If your site uses PHP, another good place to look can be the PHP error log. In order to do this though, you may need to first make some changes to the php.ini file. This article will show you how to have PHP errors written to a log file. Note: This article is working with the default php.ini file.

In order to have PHP errors written to a log file, two changes will need to be made to the php.ini file. To make the first change, find the line that has the text "; error_log = php_errors.log" on it. This text is an example, go ahead and copy it. You will see a number of lines below this one with text on them. Below these lines, add another line and then paste the text that you copied. Now, remove the text "; " from the beginning of the line. This line specifies the location of the error log and it's name. In this case, the file will be named "php_errors.log", and it will be located in your web site's document root.

To make the second change to the php.ini file, find the line that has the text "; log_errors = On" on it. Go ahead and copy the text on this line. Now, below this line, add another line and paste the text that you copied. Then, remove the "; " text from the beginning of the line. Now, save the php.ini file. Depending on your setup, you may need to restart your web server in order for the changes you made to the php.ini file to take effect.

That's it! If a PHP error occurs going forward, you should see it in the "php_errors.log" file in your website's document root.