How to Send PHP Errors to a File Rather Than the Web Browser
When you create a PHP file, you then load it to a web server to be executed in an Internet browser. The server checks the file for logical and syntax errors in the PHP code when trying to run it. If there is an error, the server stops running the file and sends the error to the user through the browser. Webmasters can't know that errors have occurred on the user's side unless it is reported, which isn't done every time a user encounters an error. Sending the errors to a log file lets the webmaster keep up with them.
Instructions
-
-
1
Log in to your server and locate the php.ini file. This file is located in the "etc" folder in the root directory. The php.ini file is where you change all of your PHP settings. This is also where you will select a log file for errors instead of a web browser.
-
2
Open the php.ini in a text editor or a code editor. Add the following lines to the php.ini file:
"#vi /etc/php.ini
error_log= /var/log/php-scripts.log"
This code in the php.ini will start to send the errors to the PHP log file. It will still send it to the web browser if you don't cut this feature off.
-
-
3
Turn off the feature that displays errors in the web browser. With the php.ini file still open, add the following line:
"display_errors = Off"
Save the php.ini file and refresh your web browser.
-
1
Tips & Warnings
You can also save the errors to a Windows Server Event log file instead of the PHP log file. Just replace "error_log = /var/log/php-scripts.log" with "error-log = syslog."
References
- Photo Credit keyboard - error image by Kirubeshwaran from Fotolia.com