Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

PHP error logs

From MoodleDocs
Revision as of 11:11, 7 April 2016 by Colin Fraser (talk | contribs)

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
 phpinfo();
then reload the web page. Look for the entry Configuration File (php.ini) Path.
When you have located php.ini open it in your favorite text editor. Find the Error handling and logging section of the php.ini file. Make sure that both display_errors = On, display_startup_errors = On and log_errors = On are present and uncommented. Check the value of error_log - this tells you the location of the file errors are logged to. If it is commented out then errors will be sent to the web server error log file. Remember, if you make any changes to this file you will need to restart the web server (or just reboot the server).
  • 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'?>' only):
 ini_set ('display_errors', 'on');
 ini_set ('log_errors', 'on');
 ini_set ('display_startup_errors', 'on');
 ini_set ('error_reporting', E_ALL);
 $CFG->debug = DEBUG_ALL;
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.

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