≡ Menu

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!

Share this on:

{ 29 comments… add one }

  • Anjanesh July 30, 2007, 3:22 am

    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");

    • rajesh April 13, 2011, 7:49 am

      thats excellent

  • Philipp July 30, 2007, 7:26 am

    You have to watch, that the logfile is writeable by the web-server process!

  • nixCraft July 30, 2007, 9:27 pm

    @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!

  • Alekc January 22, 2008, 11:48 am

    Small misspelling in title: “log fiie”

  • nixCraft January 22, 2008, 12:04 pm

    Thanks for the heads up!

  • China Landscape May 9, 2008, 9:19 am

    I have ligttpd (PHP FastCGI) and I cannot see the log.

    How can I get it in this case ?

  • Carl October 9, 2008, 3:06 pm

    “yes I did assumed that Apache or lighttpd has a write permissions”

    In the case that it doesn’t, how can this be changed?

  • nixCraft October 9, 2008, 3:13 pm


    Use chmod and chown command to set permissions.

  • Kurt October 24, 2008, 7:31 am


    Is it possible to log errors of diffrent websites in different errorfiles?

    I have a server that’s hosting different websites and I want that all of the php-errors are logged in different file. For each website a file.

    Is that possible and how do I do it?

    tnx in advance

  • nixCraft October 24, 2008, 11:28 am


    You need to setup php as FastCGI which allows the -c option. With this option you can provide custom php.ini file and error log file for each user. See this article for more info. This is lighttpd specific but you should able to setup with Apache or any other server with mod_fastcgi.


  • Carl October 24, 2008, 7:37 pm

    You might try ini_set() as well if you have trouble getting custom php.ini files to work

  • Svetainiu Kurimas October 19, 2009, 4:24 pm

    Hi, does the init_set solution also work with Apache installed on Windows? It doe snot seem to be working for me.

  • Liju December 23, 2009, 5:08 am

    I think it would need to enable this tag (log_errors = On) php.ini to get this complete.

    But I suggest it’s not a good Idea to enable on the main configuration file where a server hosted multiple sites. Just add this entries on .htaccess make sense on such case to trouble shoot.

  • lcd January 25, 2010, 4:09 pm

    You have great blog and this post is good!

  • Dhanesh Mane June 14, 2010, 7:12 am

    Hey ,

    I think if you are error_log directive is set to syslog, then logs are save at /var/log/message.
    On my server its set to syslog and the file /var/log/message is also updated but I am not able to find any php log data in this file.

    any hint wat’s happening?

  • pawel August 12, 2010, 10:21 am

    what i read was enough to solve my issue, why im writing is to see if i get one nice picture with no.16 on the right :)

  • yuri December 30, 2010, 1:31 am

    I followed the steps above and its still not working, what should I do?

  • jyoti February 13, 2012, 9:33 am

    i am using php 5.3 with xamp server and get error ‘cannot write to file(../debug.log)’ please help me becaz i am new for php…thanks in advance

  • jyoti February 13, 2012, 9:34 am

    i am using php 5.3 with xamp server and get error ‘cannot write to file(../debug.log)’ please help me becaz i am new for php ..thanks in advance

  • Alexander April 10, 2012, 7:10 am

    It seems, user, under which you run php, does not have write permissions on specified file/directory. Check parent directory permissions, if is it writable.

    I also had the same issue. I had path and settings for logging error file, but saw no file created till I set normal permissions.

  • Pavarti Izdelava July 19, 2012, 7:52 am

    Thank you for that post, it is working on my server.
    I have additional question, how do you display friendly error to user, when fatal error occur.

  • Divya October 4, 2012, 9:58 am

    What can we do in case we need to delete log file entries older than 60 days or clean up logs older than 60 days in php?

  • Dmitry Pashkevich April 26, 2013, 10:33 pm

    If you redirect error output to a custom file, you’d have to care about log rotation yourself or it’ll grow infinitely.
    If error logging is handled by the web server (default), then your web server will likely take care of that.

  • Ashish Kumar Laxkar July 26, 2013, 10:05 am

    Really helpful i have that problem from past 2 days now i resolve that… Thanks 4 support.. any update please mail…. ashish.laxkar16@gmail.com

  • Heidi April 2, 2014, 2:36 pm

    No matter if some one searches for his vital thing, thus he/she needs to be available that in detail, therefore that thing is maintained over here.

  • Neeke June 6, 2014, 3:57 pm

    error_log : no errors, no fixed format.

    My advice is SeasLog. https://github.com/Neeke/SeasLog

  • Josh February 3, 2015, 4:01 pm

    How do I set proper ownership, etc? The file is not being created, it is non-existant

  • henryvalencia608 September 27, 2015, 2:23 am

    I have a problem with my download because the server is not open always error why

Leave a Comment

   Tagged with: , , , , , , , , , , ,