Where are php errors logged ubuntu?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    The location of the error log file can be check by using phpinfo() function. Create a simple PHP file containing phpinfo() function and run it. It will display the information about PHP configuration.

    Run the above program and search for error_log directive using f3 on chrome. This will show the location of the logfile. Following is an example run on WAMP server, but the procedures will be the same as described below for every development stack.

    Open your php.ini file as specified and edit following directives to specify the path of the error log file to some other location.

    display_errors = Off

    Then you have to give the path to your log file via error_log directive as follows:


    You can find the path to the php.ini file directly using the following command on UNIX/Linux.

    php -i | grep php.ini

    PHP contains a simple and effective solution to display all log errors into the log file. It is mandatory to turn off displaying error on the server to the end user using a web browser. PHP gives lots of information related to the path, database schema and all other sorts of sensitive information. It strongly advises using error logging in place of error displaying on production web sites. This idea is helpful in displaying the error log to the developer only. PHP offers to log all the errors in a log file instead of displaying the error to the end users via a web browser. To do this first you have to turn off displaying error via a browser in the php.ini file, by setting the display_errors directive to off as mentioned above. Then you have to give the path to your log file via error_log directive as follows:
    Ex: error_log = /var/log/php-scripts.log, errors will be logged in php-scripts.log file.

    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'?>' , 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

    • Installing Moodle
    • Installation FAQ

    Where are PHP errors Ubuntu?

    5 Answers. By default, /var/log/apache2/error. log . This can be configured in /etc/php5/apache2/php.

    Where are PHP errors logged Linux?

    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.

    How do I view PHP error logs?

    On Linux, either /var/log/httpd/error_log or /var/log/apache2/error. log . These files are owned by root, so you need to be root or use sudo to see it, or read it. For those looking for a Windows solution, use php --info | findstr /r /c:"error_log" to see where the log file is.

    How do I view the error log in Ubuntu?

    If you are troubleshooting a Debian or Ubuntu derived system, examine /var/log/apache2/error. log for errors using a tool like tail or less . For example, to view the last two lines of the error log using tail , run the following command: sudo tail -n 2 /var/log/apache2/error.