W3docs

Where Does PHP Store Error Log

In this short tutorial, we are going to represent to you how to find where the PHP error log is located.

Checking the location of the error log in PHP is a common task for developers, but it can sometimes be tricky. This snippet shows where the error log is stored and how to configure it. Follow the steps below:

Using the phpinfo() Function

You can easily check the location of the error log by running the phpinfo() function:

php info function

<?php phpinfo(); ?>

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

Here are the steps you need to take:

Run the script and search for the error_log directive.

This will display the current log file location.

Open php.ini

The second step is opening the php.ini file and editing the directives to specify the error log path.

php display errors off

display_errors = Off
log_errors = On

Specify the log file path

The third step is specifying the log file path using the error_log directive. You can find the path to your php.ini file by running the following command on UNIX/Linux:

get the path to php.ini file

php --ini

On production websites, it is strongly recommended to log errors instead of displaying them to end users through a web browser. To enable this, first turn off error display as shown above. Then, specify the log file path using the error_log directive:

php error log

error_log = /var/log/php-scripts.log