PHP Log All Errors to a Log File to Get Detailed Information
PHP offers simple but effective solution to log all errors to a log fiie.
On all production web server you must turn off displaying error to end users via a web browser. Remember PHP gives out lots of information about path, database schema and all other sort of sensitive information. You are strongly advised to use error logging in place of error displaying on production web sites. The idea is quite simple -only developer should see php error log.
How do I log all php errors to a log fiie?
Just add following line to /etc/php.ini to log errors to specified file – /var/log/php-scripts.log
# vi /etc/php.ini
Modify error_log directive
error_log = /var/log/php-scripts.log
Make sure display_errors set to Off (no errors to end users)
display_errors = Off
Save and close the file. Restart web server:
# /etc/init.d/httpd restart
How do I log errors to syslog or Windows Server Event Log?
Modify error_log as follows :
error_log = syslog
How do I see logs?
Login using ssh or download a log file /var/log/php-scripts.log using sftp:
$ sudo tail -f /var/log/php-scripts.log
Updated for accuracy!
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or full RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in...
- How to keep files safe from accidental overwriting with noclobber under BASH shell
- nixCraft FAQ roundup
- nixCraft FAQ Roundup ~ July, 3, 2007
- HTTP Error 500 Internal server for php pages and solution
- How to debug a Shell Script under Linux or UNIX
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: /etc/php.ini, effective_solution, error_logging, ini file, log_php, php ini, php.ini, php_display_errors, php_error, php_error_log, php_scripts, production_web_server ~ Last updated on: April 14, 2008



It would be much better to have a single config php-file and define them there instead.
ini_set("log_errors" , "1");
ini_set("error_log" , "Errors.log.txt");
ini_set("display_errors" , "0");
You have to watch, that the logfile is writeable by the web-server process!
@Anjanesh, good point, user can set those from a php script itself.
@Philipp, yes I did assumed that Apache or lighttpd has a write permissions
Appreciate your posts!
Small misspelling in title: “log fiie”
Thanks for the heads up!
I have ligttpd (PHP FastCGI) and I cannot see the log.
How can I get it in this case ?