Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)
Asked Answered
G

30

475

I am on shared hosting and have cPanel, Apache, and PHP is run by FastCGI. Where does PHP store the error log?

Is there another way I can find the error log on a 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 file (I am using PHP version 5.2.16).

Gettogether answered 26/2, 2011 at 15:43 Comment(7)
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.Vidda
php --info | grep errorFattish
For those looking for a Windows solution, use php --info | findstr /r /c:"error_log" to see where the log file is.Xenia
It's pretty weird for me... I have hosted website and PHP logs are stored in the same file as Apache logs... On my admin panel, in logs, there is option to show full Apache error log, when I click it, there are errors about users entering places where they shouldn't, for example. But, also, in the same file there are errors that PHP shown.Dayton
@soaku if you use fastcgi apache itself does not run PHP. when you use mod_php that is apache module, apache handles php. That means errors can and probably will be in apache logs when using mod_php, but that will not be a case when using cgi or fastcgiSamellasameness
Found there: /var/log/php-fpm/www-error.log (Centos 8 default install with default Apache and remi php 7.4.2)Harty
A similar question is Find out the error_log's path.Chilopod
B
384

PHP stores error logs in /var/log/apache2 if PHP is an apache2 module. Shared hosts are often storing log files in your root directory /log subfolder. But...if you have access to a php.ini file you can do this:

error_log = /var/log/php-scripts.log

According to rinogo's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at

/usr/local/apache/logs/error_log

If all else fails you can check the location of the log file using

<?php phpinfo(); ?>
Babcock answered 26/2, 2011 at 15:52 Comment(11)
"Php stores error logs in /var/log/apache2 if php is an apache2" not on RHEL etc, where the package's name is 'httpd'. One really cannot assume that a package's name is consistent across distros.Topology
FYI to Googlers - If you're using cPanel, the master log file you're probably looking for is stored (by default) at /usr/local/apache/logs/error_logEspagnole
but check the 'error_log' section of <?php phpinfo(); ?> to confirm the pathOverspill
what if it's not an apache2 module. for example it may be an fpm package of debian running on nginx.Ish
where in the phpinfo section will it show it? in error_log all i see for key/value is 'error_log' and no actual pathPangenesis
If you specify path to file: error_log from the PHP config running as an Apache2 module, then it's not respected. The errors gets caught by the Apache2 error handler and end up in: /var/log/apache2... anyway, regardless of your error_log setting. However if you specify syslog, for the error_log, logs ends up in Syslog correctly. Quite inconsistent behavior.Submicroscopic
<?php phpinfo(); ?> gives PHP Parse error: syntax error, unexpected '<', expecting end of file in php shell code on line 1.Javelin
As you might have noticed this answer is from '11. I haven't touched PHP in like 7 years so I have no idea what the problem might be.Babcock
I guess the issue from @Javelin was trying to run an actual PHP tag (instead of pure PHP code) through... PHP shell (php -a)Uveitis
<?php phpinfo(); ?> saved the day for me. I found the correct error log path. Thanks.Herefordshire
I'm surprised that it still works that way given that this is a 10 year old answer and I haven't touched PHP in 8 years. :DBabcock
T
101

Try phpinfo() and check for "error_log"

Topology answered 26/2, 2011 at 15:49 Comment(17)
It just says error_log no path specified. I guess it maybe because it is on a shared hosting enviroment and if we had access to it we would see everyone elses site errors.Gettogether
@Gettogether does it say the same thing if you try echo ini_get('error_log');?Topology
i did not try that but it said the same in the php.ini file so what i did was change the path in the php.ini file and checked to see if it was working and it is. Does it still log all errors although i changed the path to log errors (outside document root) ? thanks phploverGettogether
@PHPLOVER: you could easily control the reporting level with the setting error_reporting(E_ALL|E_STRICT);se.php.net/manual/en/function.error-reporting.phpTopology
Mine says error_log too, no idea where to look for it. This hits nr one on google but doesn't answer it.Scevor
@Scevor did you check your php.ini or php.d/* files for the value of the setting "error_log"?Topology
@Topology Yes, same as phpinfo.Scevor
@Scevor can you just try to change it, restart your webserver (apache?) and see if you get log messages in your wanted file?Topology
@Topology Yes, didn't have su access before. Can log in as user that runs apache so would be able to read the log if I could find it. Got su access and set it to a file. Still don't know where it saved it before though.Scevor
@chelmertz, Yes echo ini_get('error_log'); returns just a string error_log. I don't see a var folder or usr folder either.Takashi
@Pacerier: the docs at [1] mention that there's only one special value and that is syslog. Thus, error_log should be a filename. Try (if on linux) "find /var -name error_log" in a shell. Also, check your web severs logs (something like /var/log/httpd or /var/log/apache if you're using Apache). 1: php.net/manual/en/errorfunc.configuration.php#ini.error-logTopology
@chelmertz, I don't have a shell to run that on, and there's no var folder in the cpanel file manager. I've also used the search function on file manager but there's no results for error_log, then I try to run <?php system("find /var -name error_log"); ?> but it's not allowed: system() has been disabled for security reasons in /home/test/test.php. Do you know what else could be tried?Takashi
If you don't have a shell, how would you read the error log's content? :) Maybe you could talk to your provider about it, since they seem to have locked down the system. They might have done something special with the logs anyways, rotated them, have a mount on that location, or anything else. I think you have a communication problem, not necessarily a technical problem :)Topology
@chelmertz, If I know where it is stored, then I can read it using normal PHP file functions.Takashi
@Takashi Wow.. the levels of indirection :) I think you would be so much better off if you considered a VPS instead of a locked down hosted environment.Topology
@chelmertz, Since it's a small site I don't need much bandwidth. VPS prices are atrocious for projects that start off small. Even the cheapest ones costs $12 per month which is $144 per year every year. Are you aware of any cheaper alternatives?Takashi
@Takashi I pay about $12 a month for mine but Digital Ocean have a small machine for $5 it seems: digitalocean.com/pricing Not too familiar with hosting but you could probably find something through google.Topology
J
69

Linux

php --info | grep error 

The terminal will output the error log location.

Windows

php --info | findstr /r /c:"error_log"

The command prompt will output the error log location.

To set the log location

Open your php.ini and add the following line:

error_log = /log/myCustomLog.log

Thanks chelmertz and Boom for these (comments on the question).

Jemine answered 28/1, 2016 at 22:14 Comment(6)
im on linux. this does not mention a log location for me.Capitalist
@Capitalist does php -info output anything? You need to make sure php is actually calling PHP to run...Jemine
Also, it is possible that php is not currently logging anything. If that's the case, you can open your php.ini, and set error_reporting to E_ALL & ~E_DEPRECATED & ~E_STRICT, or whatever errors you want to see, then set error_log to the path to the directory where you want your errors to get logged. (Note: this is not a full path to a file, just to a directory.)Jemine
I only found old logs in /var/log/httpd/ where most people recommend looking, but running php --info | grep log pointed me towards /var/www/logs where the most recent logs were located.Sapienza
Once you set the log location, don't forget to restart Apache: sudo /etc/init.d/apache2 restartTransponder
php.ini file can also be found via php --infoLastex
D
38

On a LAMP environment the PHP errors are be default directed to this below file.

/var/log/httpd/error_log

All access logs come under:

/var/log/httpd/access_log
Drummer answered 20/12, 2013 at 16:7 Comment(3)
So comment out the php error log file specification and it will just write here?Whine
It is more likely /var/log/apache2/error.log.Chilopod
For me it was /var/log/httpd-error.logKemppe
V
20

How to find your PHP error log on Linux:

sudo updatedb

[sudo] password for eric:

sudo locate error_log

/var/log/httpd/error_log

Another equivalent way:

sudo find / -name "error_log" 2>/dev/null

/var/log/httpd/error_log
Vidda answered 7/8, 2014 at 19:48 Comment(0)
A
14

It can also be /var/log/apache2/error.log if you are in Google Compute Engine.

And you can view the tail like this:

tail -f /var/log/apache2/error.log
Armitage answered 6/7, 2015 at 8:33 Comment(1)
Not only Google Compute Engine. Most LAMP installations (on Linux) as well.Chilopod
S
13

It appears that, by default, PHP does not log errors anywhere. The error_log key in php.ini is commented out in all the installs I've seen.

Generally I:

  1. look for php.ini files. locate php.ini.

  2. Search these files for the error_reporting value;

    Which should be set to whatever amalgamation of PHP log levels are enough for you.,

    For example: E_ALL & ~E_DEPRECATED & ~E_STRICT

  3. 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/.

Shirtwaist answered 26/2, 2011 at 15:43 Comment(0)
G
12

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.

Godroon answered 26/2, 2011 at 15:51 Comment(0)
C
8
php --info | grep error

This is helpful.

Cropper answered 10/5, 2018 at 7:37 Comment(2)
(It seems) this outputs the value for the PHP command line settings (e.g. /etc/php/7.1/cli/php.ini) rather than the Apache settings.Transponder
With PHP ver 7.4 I see this: # error_log => no value => no value I don't know if this means nothing is written, or if some default destination path is used instead.Ginnie
F
6

NGINX usually stores it in /var/log/nginx/error.log or access.log (on Ubuntu in any case).

Foxy answered 18/7, 2016 at 12:15 Comment(0)
O
5

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 the 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().

Oddfellow answered 13/2, 2014 at 6:23 Comment(0)
A
5

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".

Archle answered 8/1, 2015 at 17:55 Comment(0)
D
4

Wherever you want it to, if you set it in your function call:

error_log($errorMessageforLog . "\n", 4, 'somePath/SomeFileName.som');
Dorina answered 12/1, 2015 at 1:9 Comment(0)
C
4

I can guarantee you, I am not the only person who has been driven to madness at least once in a frustrating search for a log file. It seems like it should be the easiest thing to find in the whole system.

A definitive guide on where the PHP error log is stored would be a complicated bit of work. The official PHP manual does not even try to address the whole topic, because there are dependencies on systems outside PHP, such as the operating system (Linux vs. Windows, which distribution of Linux), including settings within Windows and Linux that affect the name and location of the PHP error log.

Until someone takes the time to write a complete, cross-system guide, the best you are going to get is general directions where you can inquire. Every PHP developer has had to endure agony in this pursuit, with one exception. If you work in one place and the information is provided when you first need it, then you have the information need forever, that is, until you find yourself in a new working environment. There are such fortunate people.

If the information is not given to you on a silver platter, so to speak, you have some hunting to do. The hunt is not the longest you will face in your career, but it is not the simplest either.

As is evident from the many answers already posted, a smart place to begin is the output of phpinfo(). To view it, create a PHP file containing this:

<?php
    phpinfo();

Either browse to that file or run it from the command line. If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of PHP. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.

Sample output from phpinfo() via web server and web browser

The default for error_log is no value

Default error_log in php running as an Apache mod.

Whatever the value is, it comes from the php.ini files used to configure PHP. There can be many php.ini files. Finding your way among them is confusing at first, but you do not need to deal with this to find your PHP log.

If the output from phpinfo() shows a full path to a file, that is where the log is. You are lucky.

The trick is there usually is not a full path indicated in phpinfo(). When there is not a full path, the location depends on:

  1. Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.

  2. If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution.

  3. If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).

This cheat sheet has been helpful in some situations, but I regret to have to admit it is not nearly universal. You have my condolences.

Enter image description here

Cephalonia answered 20/6, 2021 at 1:57 Comment(0)
E
3

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 in Error Handling Functions.

Englert answered 6/8, 2013 at 12:27 Comment(1)
Thanks, this solved my issue. Really lame behavior for relative definitions, to have log files spread all over the htdocs folder, and no idea where to start looking at. I would have expected to be relative to the installation folder, as other settings. +1.Emerick
P
3

If you use the php5-fpm log default, it should be under:

/var/log/php5-fpm.log
Primogenitor answered 14/11, 2014 at 13:49 Comment(0)
R
3

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.

Rama answered 21/6, 2017 at 15:55 Comment(0)
R
3

cPanel Error logs are located in:

  • /usr/local/cpanel/logs/

  • /usr/local/apache/logs/

By default Apache logs are located inside:

  • /var/log/apache

or

  • /var/log/apache2

If anyone is using a custom log location then you can check it by running this command:

cat /etc/apache2/**conf**/httpd.conf | grep ErrorLog

If you are getting an error that the apache2 directory does not exist then you can run this command to find correct location by:

whereis apache

or

whereis apache2
Rolon answered 24/3, 2019 at 4:59 Comment(0)
L
2
  1. You can go in File Manager and check the logs folder.
  2. Check the log file in a public_html folder.
  3. Check "php phpinfo()" file for where the log is stored.
Lash answered 14/12, 2018 at 11:0 Comment(2)
What is "File Manager"? Do you mean "a file manager" (common noun)? Or Windows' File Manager (though that is from the 1990s - the newer names are "File Explorer" and "Windows Explorer")? Can you elaborate? E.g., are you referring to a particular operating system? If so, which version?Chilopod
When you are using cpanel or any other hosting panel than you can see a "File Manager" in your hosting panel. link italicLash
A
2

You are on a shared environment and cannot find error log. Always check if cPanel has option Errors in your cPanel dashboard. If you are not being able to find the error log, then you can find it there.

In the 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 in a shared environment:

  • /home/yourusername/logs
  • /home/yourusername/public_html/error_log
Aplenty answered 27/5, 2019 at 11:15 Comment(1)
A screenshot would work wonders. You can edit (change) your answer (but without "Edit:", "Update:", or similar - the answer should appear as if it was written today).Chilopod
A
2

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
Armoured answered 30/1, 2020 at 11:14 Comment(0)
L
2

For PHP-FPM, just search the configuration 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
Lancer answered 12/10, 2020 at 22:51 Comment(0)
B
2

For CentOS 8 it is var/log/httpd/error_log.

Broadbill answered 12/2, 2021 at 11:48 Comment(0)
M
1

WordPress

WordPress will direct error_log() messages to /wp-content/debug.log when WP_DEBUG_LOG is set to true.

See WordPress documentation for WP_DEBUG_LOG

Micropaleontology answered 13/7, 2017 at 3:32 Comment(1)
Unless the location is overridden by an entry in file .htaccess in the WordPress root folder (e.g., logging to just above the root of the web server instead (thus inaccessible by HTTP/HTTPS)). Example: php_value error_log /var/www/pmortensen.eu/phperrors.log. Whether it works in exactly this way may or may not be configuration-dependent.Chilopod
R
1

Mine for some reason stored it in:

/var/log/php-errors.log

I'm using Ubuntu Server 16.04 (Xenial Xerus) and PHP 7.1.28.

Roundtheclock answered 15/10, 2020 at 16:30 Comment(0)
S
1

In a shared cPanel environment you cannot find the error log, if your hosting provider doesn’t provide any option in the cPanel dashboard. You can search "error" and see if your provider have any.

Otherwise normally you will find a file called "error_log" in your public_html file, which have all the PHP error recorded.

Squiggle answered 10/5, 2021 at 19:28 Comment(2)
Re "public_html file": Don't you mean "public_html folder"? (Or "public_html directory"?)Chilopod
Yes you are right public_html directorySquiggle
F
1

You can see the php errors for an account under:

/home/username/logs/domain_tld.php.error.log

You can set php error log globally and locally.

  1. Globally through WHM:

    • WHM -->> MultiPHP INI Editor --> "Editor Mode"
    • Select the version of PHP you would like to set the error log
    • Edit the parameter error_log. error_log = "/some/path" Change the filename to the desired error log file
    • Save changes
  2. Locally though cPanel:

    • CPanel -->> MultiPHP INI Editor --> "Editor Mode"
    • Select the version of PHP you would like to set the error log
    • Edit the parameter error_log. error_log = "/some/path"
    • Change the filename to the desired error log file

    Home directory will set the option for all domains, addons, and subdomains configured on the account A specific domain will limit the change to that domain, or, in the case of an addon domain, the addon and the matching subdomain

    • Save changes
  3. If PHP-fpm is enabled:

    • WHM --> MultiPHP Manager
    • Find the domain you'd like to change the error log location for
    • Click "Edit PHP-FPM"
    • Change the log location in "The error log file (error_log)" relative to the folder "logs" within the user's home directory
    • Save changes
Flick answered 16/11, 2022 at 6:46 Comment(0)
L
1

When PHP is running on a server with Apache and FastCGI, especially within environments like cPanel, the location of the PHP error logs can depend on the server's configuration. However, I can give you some common places where you might find the error log:

php.ini Configuration:

The primary configuration file for PHP, php.ini, has a directive called error_log that determines where errors should be logged. You can search for this directive in your php.ini file to see where the logs are being stored. It might look something like:

error_log = /path/to/your/php-error.log

Apache Logs:

If PHP is set up to log errors to Apache's error logs, you might find the PHP errors there. Common locations include:

  • /var/log/httpd/error_log (for some generic Linux distributions)

  • /var/log/apache2/error.log (for Debian/Ubuntu)

  • /var/log/apache/error_log (for other distributions)

cPanel-Specific Logs:

On servers with cPanel:

PHP errors might be logged to the user's home directory, like

/home/username/public_html/error_log.

cPanel has an "Errors" section where you can view the last 300 error log messages. Accessing cPanel and navigating to this section might give you direct insights without accessing the server's file system.

FastCGI:

Depending on how FastCGI is set up, it may have its own error logs separate from Apache. Check the FastCGI configuration files to see if any specific error log paths are set.

Custom Log Locations:

In some cases, developers or system administrators may specify custom log locations either within the application code (using error_log() function in PHP) or at the server level.

How to Find php.ini:

To find which php.ini file is being used by your PHP installation: Create a PHP file (e.g., phpinfo.php) with the following content:

    <?php
phpinfo();
?>

Navigate to this file in your web browser. This will display a lot of information about your PHP setup.

Look for the "Loaded Configuration File" section, which will tell you which php.ini file is being used. This file will contain the error_log directive mentioned earlier.

Always remember to remove or secure the phpinfo.php file afterwards because it can expose sensitive information about your server configuration.

Lash answered 24/8, 2023 at 12:38 Comment(0)
L
0

If you are using Ngnix you should have error.log file located within var/log/ngnix/ directory.

Lovelorn answered 4/4, 2023 at 9:18 Comment(0)
A
0

I'm using php with cpanel, and I have found error logs are created in the same folder as the php script that generated the error. Accordingly I made a cron job to run daily,

/usr/bin/php -q /home/mysite/cron.php

with the following php:

$errors="";
foreach(explode("\n",shell_exec('find . -name error_log')) as $file)
    $errors.=$file.":\n".file_get_contents($file)."\n\n\n";
if(empty($errors)) exit(0);
mail("[email protected]","php error_log",$errors);

that will daily search for error logs, and email their filenames and contents to me if found.

Acalia answered 30/9, 2023 at 6:39 Comment(1)
That seems to be more like a failed configuration than a rule.Guevara

© 2022 - 2024 — McMap. All rights reserved.