|
A user lovely lady on the Joomla Forums (k2881q) was getting errors and couldn't figure out how to see what the errors were. While a lot of hosting providers offer access to the Apache/IIS error logs, his her provider (1and1.com), didn't provide this access. They did, however, have a very useful FAQ post that I have adapted to help other Joomla users.
To log PHP warnings, errors, and notices to a file in your Joomla root directory, follow these steps:
- Download this file.
- Unzip it in your Joomla root directory.
- Modify .../index.php to include the error_include.php file and log errors from the front-end:
define( '_JEXEC', 1 ); define('JPATH_BASE', dirname(__FILE__) ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); require_once(JPATH_ROOT.DS.'error_include.php');
- Modify .../administrator/index.php to include the error_include.php file and log errors from the back-end:
define( '_JEXEC', 1 ); define('JPATH_BASE', dirname(__FILE__) ); define('DS', DIRECTORY_SEPARATOR); require_once( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once( JPATH_BASE .DS.'includes'.DS.'framework.php' ); require_once( JPATH_BASE .DS.'includes'.DS.'helper.php' ); require_once( JPATH_BASE .DS.'includes'.DS.'toolbar.php' ); require_once(JPATH_ROOT.DS.'error_include.php');
Once this is setup correctly, PHP warnings, errors, and notices will be written to a file called .error_log in your Joomla root directory. You should be able to access the file by using an FTP client or the always wonderful NinjaXplorer Component.
Note*: Files that begin with a dot (.) are considered "hidden". Some FTP programs require you to set an option to see hidden files, so make sure to turn this on if needed.
To test and make sure this is working properly, you can trigger a user error by adding this line directly after the last require_once statement above:
trigger_error('error_include.php has been included.'); Once you see the .error_log file, be sure to remove the trigger_error statement.
This method should only be used to debug issues. Once you have your issues fixed, we highly suggest removing the require_once lines added to the index.php files, the error_include.php file, and the .error_log file.
The zip file above includes the following error_include.php script:
<?php
// no direct access defined('_JEXEC') or die('Restricted access');
// Define the log file. This can be set to an absolute or relative path. define('USER_ERROR_HANDLER_LOG_FILE', JPATH_ROOT.DS.'.error_log'); define('USER_ERROR_HANDLER_ERROR_TYPES', E_ALL);
/* * The following code was taken from this post from the good folks at 1and1.com: http://faq.1and1.com/scripting_languages_supported/php/8.html */
// http://us2.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting error_reporting(0); // http://us2.php.net/manual/en/function.set-error-handler.php $old_error_handler = set_error_handler("userErrorHandler", USER_ERROR_HANDLER_ERROR_TYPES);
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars) { $time = date("d M Y H:i:s"); // Get the error type from the error number // http://www.php.net/manual/en/errorfunc.constants.php $errortype = array ( 1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024 => "User Notice", 2048 => "Strict", 4096 => "Recoverable Error", 8192 => "Deprecated", 16384 => "User Deprecated", ); $errlevel = $errortype[$errno]; //Write error to log file (CSV format) $errfile = fopen(USER_ERROR_HANDLER_LOG_FILE, "a"); fputs($errfile, "\"$time\",\"$filename: $linenum\",\"($errlevel) $errmsg\"\r\n"); fclose($errfile); if($errno != 2 && $errno != 8) { //Terminate script if fatal error die("A fatal error has occurred. Script execution has been aborted"); } }
?>
Big thanks to the folks at 1and1.com! Hope this helps people out.
|