This is a guide on how to find the location of your PHP error log. The location of this log will differ, depending on your operating system and the web server that you are using. For example: Apache and Nginx will both store this log in different folders.
However, there is a quick and easy way to pinpoint the exact location.
Use the ini_get function.
The path to PHP’s error log is stored in the php.ini configuration file. However, instead of going through the hassle of opening up the .ini file and finding the error_log directive, you can simply use the ini_get function like so:
//Use ini_get to get the error_log directive. $errorLogLocation = ini_get('error_log'); //Print out the location of the error log. echo 'Your error log is located at: ' . $errorLogLocation;
The ini_get function is useful because it will return the value of a given configuration option.
If you run the snippet above on your own server, it should print out the location of your PHP error log. In my case, it printed out the following:
Your error log is located at: c:/wamp/logs/php_error.log
The above location is for a WampServer installation on a Windows 7 machine (Apache, PHP 5). However, on your server, the code above will most likely print out a different path. For example: On an Ubuntu 18.04 server with Nginx installed as the web server, the error log might be stored at the following path:
As you can see, in some cases, even the name of the file itself will be different. This is why searching for the log file via the command line can be problematic:
sudo locate error_log
The above Linux command could fail to find the file in question. Or worse: It could lead you astray by returning the location of an older file that is no longer being used. Before you know it, you’ve wasted two hours trying to figure out why it’s blank.
Why not use phpinfo?
You can use the function phpinfo to dump out information about your PHP installation and then CTRL + F for the term “error_log”. However, it is a tad bit overkill, especially seeing as we are only looking for one configuration setting.