Error Log File Php.ini
March 28, 2016 in Apache, Howto, lighttpd, Linux, php, Security, UNIXPHP offers simple but effective solution to log all errors to a log fiie. On all production web server you must turn off displaying error to end users via a web browser. Remember PHP gives out lots of information about path, database schema and all other sort of sensitive information. You are strongly advised to use error logging in place of error displaying on production web sites. The idea is quite simple only developer should able to see php error log.
Find out path to php.iniThe default paths are as follows for popular unix like system:CentOS Linux/RHEL v5.x/6.x/7.x : /etc/php.iniUbuntu / Debian Linux (PHP 7 fpm) : /etc/php/7.0/fpm/php.iniUbuntu / Debian Linux (PHP 5.6 fpm) : /etc/php/5.6/fpm/php.iniUbuntu / Debian Linux (PHP 7 with Apache 2) : /etc/php/5.6/apache2/php.iniUbuntu / Debian Linux (PHP 5.6 with Apache 2) : /etc/php/7/apache2/php.iniFreeBSD unix server v9.x/10.x+: /usr/local/etc/php.iniYou can use the following command to find out path to php.ini: # php5-cgi -i | grep php.ini Sample outputs:# php-fpm7.0 -i | grep php.ini Sample outputs:Configuration File (php.ini) Path => /etc/php/7.0/fpm Loaded Configuration File => /etc/php/7.0/fpm/php.iniHow do I log all php errors to a log fiie?Just add following line to /etc/php.ini to log errors to specified file, say /var/log/php-scripts.log or /var/log/httpd/php-error.log: # vi /etc/php.ini Find and modify the error_log directive as follows: error_log = /var/log/php-scripts.log Make sure display_errors set to Off (no errors to end users): display_errors = Off Save and close the file. Restart web server or php7-fpm service: # /etc/init.d/httpd restart OR # systemctl restart httpd.service OR # restart php7.0-fpmHow do I log errors to syslog or Windows Server Event Log?Modify error_log as follows : error_log = syslogHow do I see logs?Login using ssh or download a log file /var/log/php-scripts.log using sftp client: $ sudo tail -f /var/log/php-scripts.log Sample outputs:Fig.01: PHP error log output Share this on:TwitterFacebookGoogle+Download PDF version Found an error/typo on this page?About the author: Vivek Git
Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's http://www.cyberciti.biz/tips/php-howto-turn-on-error-log-file.html Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions http://php.net/manual/en/function.error-log.php Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box error_reporting » « error_get_last PHP Manual Function Reference Affecting PHP's Behaviour Error Handling Error Handling Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug error_log (PHP 4, PHP 5, PHP 7)error_log — Send an error message to the defined error handling routines Description bool error_log ( string $message [, int $message_type = 0 [, string $destination [, string $extra_headers ]]] ) Sends an error message to the web server's error log or to a file. Parameters message The error message that should be logged. message_type Says where the error should go. The possible message types are as follows: error_log() log ty
Error Settings Error settings in php.ini tell PHP interpreter what kind of errors should be reported and where those should be reported. You may enable these settings in your development environment and disable few in your production environment since useful information error reports provide http://www.phpknowhow.com/configuration/php-ini-error-settings/ can also be sensitive information that outsiders shouldn't see. display_errors Default value of this setting is ‘On'. It tells PHP interpreter that if it finds a type of error mentioned in error_reporting setting then add it to the output https://tickets.suresupport.com/faq/article-1452/en/enabling_php_error_logging of the script. This basically means to show the errors in web browser. display_startup_errors Default value of this setting is ‘Off'. This tells whether to display errors that occur in PHP's startup sequence. PHP manual recommends turning this error log ‘On' only in your development environment as an aid for debugging. log_errors Default value of this setting is ‘Off'. This setting tells whether errors should be logged in web server's error log file. When you finish your application and put it live, it's a good practice that you turn ‘Off' display_errors and turn ‘On' log_errors in your production server's php.ini file. This prevents users seeing any sensitive information that can go with error reports and let you error log file still see them via web server's error log. But in development, you would rather like to see errors on the web browser and would set the settings other way around. error_reporting This setting tells what type of errors should be displayed and/or logged. There are constants that can be given as values to this setting and there is single constant (E_ALL) that represents all error types. Default value of this setting will be like below. error_reporting = E_ALL & ~E_NOTICE Above it instructs to discard errors fall into notices category. For an example, if you used an undefined variable in an echo() statement, PHP generates a notice. This can be a useful feature in debugging. Think that you defined a variable as $name but mistyped it in the echo() statement as $nmae then PHP interpreter would let you know it. So, make sure you enable notices in your development environment by using just E_ALL as below. error_reporting = E_ALL E_STRICT was introduced in PHP 5.0.0 and till PHP 5.4.0, it was not included in E_ALL. So, if you are using a version in-between, have the error_reporting setting as below in your development environment.
error_reporting = E_ALL | E_STRICT Where to Head from Here... You Are at : Configuration > php.ini Error Settings Previous Article : Basics of php.ini Next Article : Changing php.ini Settings at Runtime Share with Your Peerslogging for your scripts by changing the PHP settings for your account. Details on how to do this can be found at http://www.suresupport.com/faq/71/468.To enable PHP error logging, you can add the following directives either to the global php.ini file of your hosting account, or to a php.ini file in the folder where you want error logging enabled: error_reporting = E_ALL | E_STRICT log_errors = Ondisplay_errors = Offerror_log = /home/%USER%/private/php-errors.log Replace %USER% with the username of your hosting account (your Control Panel username). The above settings are recommended. You can alter them according to your needs. The line error_reporting = E_ALL | E_STRICT defines which errors are to be recorded. E_ALL specifies that all errors and warnings should be logged. E_STRICT instructs the PHP interpreter to suggest code changes that will make sure the PHP code is compatible with future versions of PHP (especially PHP6). You can check all error_reporting predefined constants here:http://php.net/manual/en/errorfunc.constants.php The line log_errors = On enables recording of errors in the log file on the server. If this runtime option is set to Off, no errors will be recorded in the log file. display_errors = Off disables error displaying in the browser. If you set this option to On, then errors will be displayed in the browser when the PHP script is executed. The line error_log = /home/%USER%/private/php-errors.log will set the PHP interpreter to record its errors in the specified file in the private folder on your account. Remember to replace %USER% with the username of your hosting account. If you want, you can choose another folder or a different file to store the logs in. 2002-2016©Suresupport.com Contact: support Contact @ Us suresupport for more information .com