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,
- PHP error log file in WordPress
- Path of PHP error log file in Apache
- PHP error log location in Ubuntu
- Path of PHP error log file in Nginx
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
1 2 3 4 5 6 7 8 9 |
<?php 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!" ); ?> |
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.
1 |
<?php phpinfo(); ?> |
Output:
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,
/wp-content/debug.log
Path of PHP Error Log File in Apache
/usr/local/apache2/logs/error_log
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
/var/log/nginx/error.log
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 https://www.php.net/
[helpie_faq group_id=’6279’/]
Also Check:
- Best Way to Download Video From YouTube
- Explain Different Parts of The URL With Example
- What Does int(11) mean in MySQL With Example
- Import and Export CSV file in PHP
Happy Coding..!
[…] Also Read: Complete Guide PHP Error Log […]
[…] Leer también: Guía completa de registro de errores de PHP […]
[…] Complete Guide PHP Error Log […]
[…] Complete Guide PHP Error Log […]
[…] Complete Guide PHP Error Log […]
[…] Complete Guide PHP Error Log […]