To log PHP errors you will want to edit your server/domain's php.ini file. If you require a refresher on how to locate/edit the php.ini file of your server, feel free to check out our additional article:
How can I edit the php.ini file? How can I edit the php.ini file?
Once in your php.ini file, input the following:
; log PHP errors to a file
log_errors = on
error_reporting = 32767
error_log = /path/to/file
Be sure to change /path/to/file to the file path where you want the logs to be saved.
- In the above code, the integer 32767 is used to denote the "E_ALL" level of error reporting in legacy PHP versions. Depending on the specific version of PHP you are running on that domain, the integer values may correspond differently to the error verbosity levels. 32767, however, should continue to function as "E_ALL" in newer versions of PHP.
- Visit http://www.php.net/manual/en/errorfunc.constants.php for information on the different levels of error reporting available and their corresponding integer codes.
- It is best to keep the log in a directory which is NOT web-accessible; some PHP errors may expose vulnerabilities or sensitive information that could be useful to a visitor with malicious intent.
- Depending on the level of verbosity you have selected for your PHP error logging and the frequency of errors/warnings generated, the PHP error logging file could grow very large very quickly. Be sure to keep a close eye on the size of this file and to only have the error logging enabled if you are actively debugging potential site coding issues.