- Documentation
- PHP error logs
- How to enable and check PHP error logs
- Error Logs
- See also
- How to: The PHP Error Logs
- What is the PHP Error Logs?
- Where to find the PHP Error Logs?
- Hosting Service Admin Panel
- Through WordPress directly
- With the Meow Apps Dashboard
- With a Dedicated Plugin
- Enable the PHP Error Logs through WordPress
- Additional Information
- How To Check PHP Error Log WordPress
- What is a PHP Error Log?
- How to Check PHP Error Log
- Method 1: Error Logging using the WordPress configuration (wp-config.php) file
- Method 2: Log errors via the php.ini file
- Method 3: Log the error via the HTAccess file
Documentation
If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.
PHP error logs
PHP can be set up to log errors in a variety of different ways: two of these involve the use of the php.ini file and the ini_set command.
How to enable and check PHP error logs
PHP can be set up to log errors in a variety of different ways: two of these involve the use of the php.ini file and the ini_set command.
- Using the php.ini file: The log settings are contained in the php.ini file stored on the server. If you don’t know where that is, edit your Moodle config.php and add the following as the second line
- Using ini_set commands: If you are using Moodle 1.7 or higher, the previous steps are not enough. In those versions error logging parameters are dependant on certain administrative settings that you specify in the debugging section. The problem is that if you can’t access the administrative pages, you can’t set the debugging options. So the only way to modify them is by adding the following lines to your config.php file, just before the last line (the one containing a single’?>’ , if present):
ini_set ('display_errors', 'on'); ini_set ('log_errors', 'on'); ini_set ('display_startup_errors', 'on'); ini_set ('error_reporting', E_ALL); $CFG->debug = 30719; // DEBUG_ALL, but that constant is not defined here.
This will enable the same settings specified above even if Moodle sets them otherwise. Important: Remember to put them just before the last line of config.php.
Debug Mode for version 3.9: @error_reporting(E_ALL | E_STRICT); @ini_set(‘display_errors’, ‘1’); $CFG->debug = (E_ALL | E_STRICT); $CFG->debugdisplay = 1;
Error Logs
The default settings of the PHP Error Log file varies from OS to OS. The location of the error log file itself can be set manually in the php.ini file. On a Windows server, in IIS, it may be something like «‘error_log = C:\log_files\php_errors.log'» in Linux it may be a value of «‘/var/log/php_errors.log'». The php_errors.log file may be required to be manually created, which would mean that the ownership and rw permissions will need to be set accordingly.
See also
How to: The PHP Error Logs
Something wrong happened while you were using a plugin in WordPress (freeze, or something similar) or your website is crashing with a blank screen… or anything else? Checking your PHP Error Logs is the first reaction you should have.
The PHP Error Logs is not the Access Error Logs (which is the error related to your web server and not PHP).
This article is still being written and updated. Don’t hesitate to ask questions in the comments, we’ll try to share more useful information over time.
What is the PHP Error Logs?
PHP Error Logs contain errors related to programming errors but also memory, space, and timeout issues. They are really important to troubleshoot issues.
Please note that the PHP Error Logs is rarely empty (as warnings are also logged in them).
Where to find the PHP Error Logs?
Hosting Service Admin Panel
Usually, you can access them through the administration system shared by your hosting service (not the WordPress one; it can be Plesk, cPanel, or their own system). Here are how to find it for the famous hosting services:
- Siteground: Visit Tools, Site, File Manager. In there, you’ll find a folder called logs. For specific PHP errors, look into the public_html folder of the domain. You’ll find a php-errors.log.
Please let me know if you know how to get the PHP Error Logs for more hosting services 🙂
Through WordPress directly
If you are lucky, your PHP Error Logs are accessible through WordPress. Depending on your hosting service, it might work, or not. If the file is not found, or empty, it’s probably that it is disabled. If you can’t find them, or if they are empty and you have issues, contact your hosting service and ask them for access to your PHP Error Logs (and if they are good, for troubleshoot about your issue at the same time).
With the Meow Apps Dashboard
The Meow Apps Dashboard reads automatically, if available, your PHP Error Logs, splits it into the different warnings and errors, color those messages and display them nicely. It’s the simplest way of checking the errros. The Meow Apps Dashboard is available in all the plugins by Meow Apps (it’s a common library to all of them).
With a Dedicated Plugin
There are a few plugins which are made to read the PHP Error Logs. They work the same way as the Meow Apps Dashboard, usually a bit simpler, they just display whatever is in the file. You can try Error Log Monitor.
Enable the PHP Error Logs through WordPress
There are some ways to get the errors to be written to a specific files through WordPress. This also highly depends on how your hosting service is set up, and if they allow it to be done. Please give it a try! You can simply add this in your wp-config.php file, right before the /* That’s all, stop editing! Happy blogging. */ line.
// Enable WP_DEBUG mode define( 'WP_DEBUG', true ); // Enable Debug logging to the /wp-content/debug.log file define( 'WP_DEBUG_LOG', true ); // Disable display of errors and warnings define( 'WP_DEBUG_DISPLAY', false ); @ini_set( 'display_errors', 0 );
Note: this code the one recommended officially by WordPress for debugging purposes.
Additional Information
There is an additional thread on StackOverflow where people are discussing this, have a look here: Where does PHP store the error log?
How To Check PHP Error Log WordPress
PHP is the programming language used to create WordPress. When a user requests a web page with PHP code, the PHP module (Apache or Nginx) processes the code on the server. The processing may result in a PHP error. That means there is an issue with the PHP code. Errors can vary; they can be as simple as omitting a semicolon or complicated as calling a wrong variable.
In this article, we will discuss the meaning of PHP error logs, their usefulness, and how you can monitor them using different methods.
What is a PHP Error Log?
A PHP error log list contains warnings and errors resulting from language runtime and is saved in a file. The code used in creating the WordPress is PHP; therefore, it takes care of WordPress errors and logs messages.
There are many reasons for errors. There may be typos in a line of code, or the code may be okay; however, an unexpected event occurred during execution. In any case, the developers want you to be aware of this, so they write code to log the message to a file. The error log is a chronological list of these messages.
The error log is very useful for figuring out why WordPress doesn’t work as expected. If it consumes too much server resources, the plugin is corrupted, or the page is not loading, the log will let you know why. If you find yourself in a situation where WordPress doesn’t work, logs may be the only way to see what’s going on behind the scenes.
How to Check PHP Error Log
There are different ways to monitor PHP Error Log, and some of them include;
- Using the wp-config.php file
- Error Logging via the php.ini file
- Error Logging via the HTAccess file
Method 1: Error Logging using the WordPress configuration (wp-config.php) file
The simplest method to implement PHP error logging on your WordPress site is by adding a few simple lines of code to your wp-config.php file. The WordPress wp-config.php file can be used to set various PHP settings to change the PHP installation functionality. In this way, we leverage this feature through a basic error monitoring implementation on your website. You can follow the following steps:
Step 1: Create a log file
Create a blank file named «PHP-error.log». This file is used as a PHP error log for your Website. It is required that your server has access to this file, therefore ensure permissions are configured appropriately. The file can be placed in any directory, but for security reasons, it is recommended that it be placed in the root directory of your Web site, which is accessible from the Internet. Once you have created and put a writable file in place, note the path of the directory and go to the last step.
Step 2: Adding the code
Then open the configuration file on your website (you will find it in the root WordPress directory) and insert the code below above this line, “That’s all, stop editing! Happy blogging.”:
// log PHP errors
@ini_set('log_errors','On'); // enable or disable PHP error logging (use 'On' or 'Off')
@ini_set('display_errors','Off'); // enable or disable public display of errors (use 'On' or 'Off')
@ini_set('error_log','/home/path/logs/php-errors.log'); // path to server-writable log file
After inserting the code, edit the third line with the full directory path of the PHP-error.log file created initially. Upload to your server and access it. All PHP errors are now logged in your PHP-error.log file, so you can monitor and fix errors without wasting time.
Method 2: Log errors via the php.ini file
Suppose you can open the php.ini file of your website or can implement initiation files «by directory». In that case, this method can help you monitor PHP errors for any site, not just those using WordPress technology. The process is almost the same as the previous method and needs the following steps:
Step 1: Create a log file
Same as the first method, create an empty file with the name «PHP-error.log». This file acts as a PHP error log for a website. Your server must be capable of writing this file; therefore, ensure you set proper permissions. You can place the file in any directory; however, to make things safer, it would be best that you position them above the root directory of an accessible site.
Step 2: Add the code
Then, open the php.ini file of the website and enter the code below:
;;; log php errors
display_startup_errors = false
display_errors = false
html_errors = false
log_errors = true
track_errors = true
error_log = /home/path/logs/php-errors.log
error_reporting = E_ALL | E_STRICT
log_errors_max_len = 0
This code is still configured to achieve the best error handling for the production server. All you need to edit is the full path of the log file. During website development, you might need to modify some variables to show errors, startup errors, repeated errors, etc.
Method 3: Log the error via the HTAccess file
Finally, we will see how to enable PHP error logging through the HTAccess. With the HTAccess file enabled on your website, this method is very effective and allows you to log.
PHP errors on any Website, not just those that operate using WordPress.
Step 1: Create a log file
Like we did for other methods, create a blank «PHP-error.log». The file will be a PHP error for your site. Your server must be able to access this file, therefore, set all permissions properly. The file can be on any .directory. Just ensure it is placed above your site’s root directory, which is accessible on the web. After creating, saving, and installing this file, note the full directory path and proceed to the last step.
Step 2: Add the magic code
Next, open your site’s root .htaccess file and add the following code:
# log php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_value error_log /home/path/logs/php-errors.log