I am on shared hosting and have Cpanel, Apache, PHP is run by fastcgi. Where does PHP store the error log?
Is there any other way I can find the error log on shared hosting environment instead of having to go through entire site structure to look for error_log files?
I have access to the php.ini
(I am using PHP version 5.2.16).
This question is related to
error-handling
php
The best way is to look in your httpd.conf file and see what the default is. It could also be overridden by your specific virtual host. I start by looking at /etc/httpd/conf/httpd.conf
or /etc/apache2/httpd.conf
and search for error_log. It could be listed as either /var/log/httpd/error_log or /var/log/apache2/error_log
but it might also be listed as simply logs/error_log
.
In this case it is a relative path, which means it will be under /etc/httpd/logs/error_log
. If you still can't find it check the bottom of your httpd.conf file and see where your virtual hosts are included. It might be in /etc/httpd/conf.d/<- as "other" or "extra". Your virtual host could override it then with ErrorLog "/path/to/error_log".
If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log
i.e generally /usr/local/apache2/logs/error_log
. Else, if you have installed it from repository, you will find it at /var/log/apache2/error_log
.You can set the path in your php.ini
also and verify it by invoking phpinfo()
.
If You use php5-fpm log default should be under
/var/log/php5-fpm.log
You should use absolute path when setting error_log variable in your php.ini file, otherwise, error logs will be stored according to your relative path.
error_log = /var/log/php.errors
Other solution would be writing simple script which would list all error logs files from directory tree.
cPanel Error logs are located in:
/usr/local/cpanel/logs/
/usr/local/apache/logs/
By default Apche logs are located inside:
/var/log/apache
or
/var/log/apache2
If anyone is using custom log location then you can check it by running this command:
cat /etc/apache2/conf/httpd.conf | grep ErrorLog
If you are getting error that apache2 directory does not exist then you can run this command to find correct location by:
whereis apache
or
whereis apache2
something like this :
sudo locate error.log | xargs -IX grep -iH "errorlog" X
or
sudo locate error_log | xargs -IX grep -iH "errorlog" X
or
sudo find / -iname "error?log" 2>/dev/null | xargs -IX grep -iH "errorlog" X
A bit late and a lot of great answers were given, but mine for some reason stored it in:
/var/log/php-errors.log
I'm using Ubuntu Server 16.04 and PHP 7.1.28.
You are on share environment and cannot find error log, always check if cPanel has option Errors on your cPanel dashboard. If you are not being able to find error log, then you can find it there .
On cPanel search bar, search Error, it will show Error Pages which are basically lists of different http error pages and other Error is where the error logs are displayed.
Other places to look on shared environment: /home/yourusername/logs /home/yourusername/public_html/error_log
Search the httpd.conf file for ErrorLog
by running cat <file location> | grep ErrorLog
on the command line. For example:
$ cat /etc/apache2/httpd.conf | grep ErrorLog
Output:
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
ErrorLog "/private/var/log/apache2/error_log"
Find the line that starts with ErrorLog
and there's your answer.
Note: For virtual hosts, you can edit the virtual hosts file httpd-vhosts.conf
to specify a different log file location.
When configuring your error log file in php.ini, you can use an absolute path or a relative path. A relative path will be resolved based on the location of the generating script, and you'll get a log file in each directory you have scripts in. If you want all your error messages to go to the same file, use an absolute path to the file.
See more here: http://www.php.net/manual/en/ref.errorfunc.php#53025
It can also be /var/log/apache2/error.log
if you are in google compute engine.
And you can view tail like this:
tail -f /var/log/apache2/error.log
For PHP-FPM just search config file for error_log
:
# cat /etc/php-fpm.d/www.conf | grep error_log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
Wordpress will direct error_log()
messages to /wp-content/debug.log
when WP_DEBUG_LOG
is set to true.
for centos 8 var/log/httpd/error_log
On a LAMP environment the php errors are default directed to this below file.
/var/log/httpd/error_log
All access logs come under:
/var/log/httpd/access_log
It appears that by default php does not log errors anywhere, the error_log
key in php.ini is commented out in all the install's I've seen.
Generally I:
locate php.ini
.Search these files for the error_reporting
value;
Which should be set to whatever amalgamation of php log levels are enough for you.,
Eg: E_ALL & ~E_DEPRECATED & ~E_STRICT
Check the error_log
value to make sure it points to an actual place and is not commented out.
The default value doesn't give a full path, only a file name, I don't know where this path resolves to normally. Probably /var/log/
.
Try phpinfo()
and check for "error_log"
whereever you want it to, if you set it your function call: error_log($errorMessageforLog . "\n", 4, 'somePath/SomeFileName.som');
php --info | grep error
This is helpful. commented by sjas on question. so i included it as a answer.
How do find your PHP error log on Linux:
eric@dev /var $ sudo updatedb
[sudo] password for eric:
eric@dev /var $ sudo locate error_log
/var/log/httpd/error_log
Another equivalent way:
eric@dev /home/eric $ sudo find / -name "error_log" 2>/dev/null
/var/log/httpd/error_log
php --info | grep error
The terminal will output the error log location.
php --info | findstr /r /c:"error_log"
The command prompt will output the error log location
Open your php.ini
and add the following line:
error_log = /log/myCustomLog.log
Thanks @chelmertez, @Boom for these (comments on the question).
NGINX usually stores it in /var/log/nginx/error.log or access.log. (On Ubuntu in any case)
Source: Stackoverflow.com