Complete Guide PHP Error Log

In this complete guide on PHP Error Log we discuss PHP Error Log Location on all operating system and the server. Also we talk about How to create an error log file in PHP with user defined path.

We discuss complete error log path for,

  1. PHP error log file in WordPress
  2. Path of PHP error log file in Apache
  3. PHP error log location in Ubuntu
  4. Path of PHP error log file in Nginx
Complete Guide: PHP Error Log
Complete Guide: PHP Error Log

Before we start with these, we have to know how we create an Error log file in PHP? and store a user-defined path.

How to Create a PHP Error Log File

Code Explanations:

  • ini_set() function used to set the php.ini configuration at the time of file execution.
  • We ini_set() function for showing errors and notices at the time of PHP file execution.
  • After that, we use the same function to set the path of the PHP error log file.
  • At last, we use error_log() to store the error messages.

How to Check PHP Error Log File Location?

If anyone wants to check the current path of the error log file, then they have just created a simple PHP file and execute it with the PHP info function.


error log path
Check error log path

PHP Error Log File in WordPress

To create an error log file in WordPress, you will need to add the following code in your wp-config.php file just below the WP_DEBUG line.

define( 'WP_DEBUG_LOG', true );

Now save the file and you can see the log file in following path,


Path of PHP Error Log File in Apache


PHP Error Log Location in Ubuntu

By default, /var/log/apache2/error.log.
This can be configured in /etc/php5/apache2/php.ini.

Path of PHP Error Log File in Nginx


To check the data on the file, run the following command on terminal,

sudo tail /var/log/nginx/error.log -n 200

If you want to know more about error log in PHP you can check the official site

FAQs: PHP Error Log

  • How do I view PHP error logs?

    Ans: Using PHP info <?php phpinfo(); ?> function to get path of error log file and check the logs on file.

    Was this article helpful?
  • How do I fix PHP errors?

    Ans: To fix the PHP error, we have read the error message carefully than we change the source code according to it.

    Was this article helpful?
  • How do you write an error log?

    ini_set(“log_errors”, 1);

    //set path where error log file will save
    ini_set(“error_log”, “path-to-store/php-error.log”);

    //used to store error data
    error_log( “Hello, errors!” );

    Was this article helpful?
  • Also Check:

    Happy Coding..!

    Was this article helpful?
    My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
    Posts created 189

    5 thoughts on “Complete Guide PHP Error Log

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Related Posts

    Begin typing your search term above and press enter to search. Press ESC to cancel.

    Back To Top