≡ Menu

php scripts

PHP 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 see php error log.

How do I log all php errors to a log fiie?

Just add following line to /etc/php.ini to log errors to specified file – /var/log/php-scripts.log
# vi /etc/php.ini
Modify error_log directive
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:
# /etc/init.d/httpd restart

How do I log errors to syslog or Windows Server Event Log?

Modify error_log as follows :
error_log = syslog

How do I see logs?

Login using ssh or download a log file /var/log/php-scripts.log using sftp:
$ sudo tail -f /var/log/php-scripts.log

Updated for accuracy!

No more php4 updates after 31st Dec 2007

There will be no updates after 31-Dec-2007 for PHP 4 version. According to the PHP development team ~ support for PHP 4 will continue until the end of this year only

You can easily upgrade to PHP 5 but please keep it mind that - few old php scripts may not work. Following application does works 100% with PHP 5 and MySQL 5:

a) WordPress blog software
b) Vbulletin and PHPBB forum software
c) Phpmyadmin MySQL admin software
d) Drupal 5.x CMS and many other softwares

Migrating from PHP 4 to PHP 5

PHP4 or PHP5 do not have any problem to execute php3 files. The only problem is you need to force PHP4 or PHP5 to understand .php3 file extension as a php script.
[click to continue…]