Find out path to php.ini
The default paths are as follows for popular unix like system:
- CentOS Linux/RHEL v5.x/6.x/7.x : /etc/php.ini
- Ubuntu / Debian Linux (PHP 7 fpm) : /etc/php/7.0/fpm/php.ini
- Ubuntu / Debian Linux (PHP 5.6 fpm) : /etc/php/5.6/fpm/php.ini
- Ubuntu / Debian Linux (PHP 7 with Apache 2) : /etc/php/5.6/apache2/php.ini
- Ubuntu / Debian Linux (PHP 5.6 with Apache 2) : /etc/php/7/apache2/php.ini
- FreeBSD unix server v9.x/10.x+: /usr/local/etc/php.ini
You can use the following command to find out path to php.ini:
# php5-cgi -i | grep php.ini
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, 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-fpm
How 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
Shamelessly stolen from
cyberciti.biz
With .htaccess file
# enable PHP error logging
php_value error_reporting
VALUE
php_flag log_errors on
php_value error_log FULL/PATH/php_error_your_domain.log
VALUE
The value used defines the level or error reporting you require, for example:
- -1 = ALL errors, not recommended but can be useful when used sparingly.
- 30719 = Same as E_ALL, less info than -1
- 30711 = E_ALL but not E_NOTICE
- 30709 = E_ALL but not E_NOTICE or E_WARNING
- 22517 = E_ALL but not E_NOTICE or E_WARNING or E_DEPRECATED
Create the php_error_your_domain.log file.
Shamelessly stolen from
here