482

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

7
  • 40
    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. Commented Aug 7, 2014 at 19:49
  • 135
    php --info | grep error
    – sjas
    Commented Aug 27, 2014 at 13:21
  • 14
    For those looking for a Windows solution, use php --info | findstr /r /c:"error_log" to see where the log file is.
    – Boom
    Commented May 13, 2015 at 17:00
  • 1
    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.
    – user5147563
    Commented Mar 12, 2017 at 10:35
  • @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 fastcgi Commented Jun 7, 2018 at 9:20

30 Answers 30

386

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(); ?>
11
  • 24
    "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.
    – chelmertz
    Commented May 14, 2013 at 9:07
  • 30
    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_log
    – rinogo
    Commented Dec 4, 2013 at 19:11
  • 5
    but check the 'error_log' section of <?php phpinfo(); ?> to confirm the path
    – doub1ejack
    Commented May 27, 2014 at 19:44
  • 2
    where in the phpinfo section will it show it? in error_log all i see for key/value is 'error_log' and no actual path Commented Aug 28, 2017 at 21:51
  • 2
    I guess the issue from @Hi-Angel was trying to run an actual PHP tag (instead of pure PHP code) through... PHP shell (php -a) Commented Jun 19, 2020 at 7:01
103

Try phpinfo() and check for "error_log"

17
  • 18
    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.
    – PHPLOVER
    Commented Feb 26, 2011 at 15:56
  • 8
    @PHPLOVER does it say the same thing if you try echo ini_get('error_log');?
    – chelmertz
    Commented Feb 26, 2011 at 16:27
  • 2
    @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.php
    – chelmertz
    Commented Feb 26, 2011 at 16:39
  • 4
    Mine says error_log too, no idea where to look for it. This hits nr one on google but doesn't answer it.
    – HMR
    Commented Jun 10, 2014 at 7:30
  • 1
    @Pacerier 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.
    – chelmertz
    Commented Mar 2, 2015 at 12:57
70

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

6
  • 9
    im on linux. this does not mention a log location for me.
    – Sirex
    Commented Mar 24, 2016 at 1:27
  • 1
    @Sirex does php -info output anything? You need to make sure php is actually calling PHP to run...
    – Cullub
    Commented Apr 8, 2016 at 14:43
  • 1
    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.)
    – Cullub
    Commented Apr 8, 2016 at 14:52
  • 1
    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.
    – ChrisBob
    Commented Feb 2, 2017 at 16:38
  • 1
    Once you set the log location, don't forget to restart Apache: sudo /etc/init.d/apache2 restart Commented Jul 3, 2018 at 0:08
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
3
  • So comment out the php error log file specification and it will just write here?
    – User
    Commented Feb 3, 2015 at 16:20
  • It is more likely /var/log/apache2/error.log. Commented Sep 18, 2021 at 18:55
  • For me it was /var/log/httpd-error.log
    – Prid
    Commented Jul 29, 2022 at 0:58
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
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
1
  • Not only Google Compute Engine. Most LAMP installations (on Linux) as well. Commented Sep 28, 2021 at 16:03
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/.

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.

0
9
php --info | grep error

This is helpful.

2
  • 3
    (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. Commented Jul 3, 2018 at 0:10
  • 6
    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. Commented Dec 9, 2020 at 13:32
6

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

6

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

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

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

4

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

error_log($errorMessageforLog . "\n", 4, 'somePath/SomeFileName.som');
3

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

/var/log/php5-fpm.log
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.

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

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.
    – drakorg
    Commented May 2, 2014 at 0:56
2

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

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
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). Commented Sep 26, 2021 at 14:01
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.
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? Commented Sep 28, 2021 at 16:35
  • When you are using cpanel or any other hosting panel than you can see a "File Manager" in your hosting panel. link italic Commented Oct 6, 2022 at 8:47
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
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
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.

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

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. Commented Sep 26, 2021 at 14:08
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.

2
  • Re "public_html file": Don't you mean "public_html folder"? (Or "public_html directory"?) Commented Oct 4, 2021 at 20:40
  • Yes you are right public_html directory Commented Dec 19, 2021 at 6:18
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
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.

0

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

-1

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.

1
  • 1
    That seems to be more like a failed configuration than a rule. Commented Oct 3, 2023 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.