How to Find Error Log Location in PHP
-
Use the
php --info
Command to Locate the File Location of Error Log in PHP -
Use the
phpinfo()
Function to Locate theerror_log
Directives to Find the Error Log in PHP - Use the XAMMP Control Panel to View the Error Log in PHP in Windows
We will introduce a method to locate and view the error log in PHP in the apache2
module using the php --info
command. We can use this command in both Windows and Linux systems. This method will locate the location of the PHP error log files in the system.
We will also introduce another method to locate the error log in PHP in Windows system using the phpinfo()
function. This method helps to find the error_log
directive and its location in the system.
This article will introduce another method to see the PHP error log using the XAMPP Control Panel. This method works for the apache web server.
Use the php --info
Command to Locate the File Location of Error Log in PHP
We can use the php --info
command to locate the file location of the error log in PHP in the apache module. For windows, use the php --info | findstr /r /c:"error_log"
command in the command prompt. In the case of Linux, use the command php --info | grep error
. These commands will output the error log location in the terminal.
We can use the cat
command to view the error log in PHP. The cat
command stands for concatenate, and it shows the contents of a file in Linux/Unix system. The error.log
file contains the error log. The file resides in the var/log/apache2
directory. For example, open the terminal and write the command sudo cat /var/log/apache2/error.log
. The command will show the contents of the error.log
file in the terminal. It contains the list of errors and notices encountered in PHP.
Example Code:
cat /var/log/apache2/error.log
Output:
[Mon May 10 13:59:14.803938 2021] [php7:error] [pid 185143] [client ::1:56320] PHP Parse error: syntax error, unexpected '<', expecting end of file in /var/www/html/index.php on line 21
[Mon May 10 14:01:00.048212 2021] [php7:error] [pid 185108] [client ::1:56340] PHP Fatal error: Uncaught Error: Call to undefined function php_func() in /var/www/html/index.php:8\nStack trace:\n#0 {main}\n thrown in /var/www/html/index.php on line 8, referer: http://localhost/index.php
Use the phpinfo()
Function to Locate the error_log
Directives to Find the Error Log in PHP
We can use the phpinfo()
function to check the location of error_log
directives in PHP in Windows. We can use this method to find the error log location in the Linux system as well. Once we find the error log location, we can navigate the file structure and see the error log. For example, write the function phpinfo()
in a PHP file and open the file in the browser. Locate a directive error_log
and check the location of the directive right beside it. Navigate to the file location, and a text file named php_error_log
appears there. Open the file to view the error logs in PHP. If the location does not appear in the phpinfo
file, navigate through the xammp
folder and click the apache
folder. Inside the apache
folder, there exists a folder logs
, and inside it, there is a text file error
, that contains the error log.
The example below displays the error logs located in the error
file in the xammp/apache/logs
location.
Example Code:
# php 7.x
<?php
phpinfo();
?>
cd xampp/apache/logs/
Output:
[Tue Apr 27 10:53:49.699720 2021] [php7:error] [pid 13372:tid 1900] [client ::1:51930] PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\\xampp\\htdocs\\upload.php:20\nStack trace:\n#0 {main}\n thrown in C:\\xampp\\htdocs\\upload.php on line 20, referer: http://localhost/upload.php
[Tue Apr 27 10:54:06.232963 2021] [php7:error] [pid 13372:tid 1908] [client ::1:51934] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in C:\\xampp\\htdocs\\upload.php:20\nStack trace:\n#0 C:\\xampp\\htdocs\\upload.php(20): PDOStatement->execute()\n#1 {main}\n thrown in C:\\xampp\\htdocs\\upload.php on line 20, referer: http://localhost/upload.php
Use the XAMMP Control Panel to View the Error Log in PHP in Windows
We can use the XAMMP Control Panel to see the error log in PHP for the apache module in Windows. For example, open the xammp application and locate the apache module. In the action columns, find the Logs button. Click on the Logs button, and some options appear. Choose the option Apache (error.log)
. Then the error
text file opens, which contains the error log.
The output section below shows the error logs of the error
text file. The file contains the random errors encountered.
Output:
[Tue Apr 27 10:53:49.699720 2021] [php7:error] [pid 13372:tid 1900] [client ::1:51930] PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\\xampp\\htdocs\\upload.php:20\nStack trace:\n#0 {main}\n thrown in C:\\xampp\\htdocs\\upload.php on line 20, referer: http://localhost/upload.php
[Tue Apr 27 10:54:06.232963 2021] [php7:error] [pid 13372:tid 1908] [client ::1:51934] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound in C:\\xampp\\htdocs\\upload.php:20\nStack trace:\n#0 C:\\xampp\\htdocs\\upload.php(20): PDOStatement->execute()\n#1 {main}\n thrown in C:\\xampp\\htdocs\\upload.php on line 20, referer: http://localhost/upload.php
Subodh is a proactive software engineer, specialized in fintech industry and a writer who loves to express his software development learnings and set of skills through blogs and articles.
LinkedIn