Question

PHP Error Log Location: Apache, FastCGI, and cPanel

phperror-handling

Question

I use shared hosting with cPanel, Apache, and PHP running through FastCGI. Where does PHP store its error log?

Is there a way to find the PHP error log in a shared-hosting environment without searching the entire site directory for files named error_log?

I have access to php.ini and am using PHP 5.2.16.

Short Answer

PHP does not have one universal error-log location. The active PHP configuration determines whether errors are written to a file, sent to the web server log, sent to a hosting control-panel log viewer, or discarded. You will learn how to inspect the active settings, identify the relevant log, and safely configure a project-specific log when your host permits it.

Concept

PHP error logging is controlled primarily by configuration directives, especially log_errors and error_log.

  • log_errors decides whether PHP writes errors to a log destination.
  • error_log specifies that destination when PHP is configured to use a file or another supported target.
  • display_errors controls whether an error is shown in the browser. It is separate from logging.

For example, this configuration tells PHP to log errors to a particular file:

log_errors = On
error_log = "/home/account/logs/php-errors.log"

If error_log is empty or unavailable, PHP may use the server's configured error log instead. With Apache and FastCGI, that can mean Apache's error log, a FastCGI/PHP handler log, or a host-managed location. On shared hosting, the hosting provider controls much of this setup, so there is no reliable path that applies to every cPanel account.

The important idea is: the active configuration, not PHP itself, determines where errors go. A php.ini file you can edit is useful only if it is actually loaded by the FastCGI PHP process and the host allows those directives to be changed.

PHP 5.2.16 is obsolete and no longer receives security fixes. Use a supported PHP version when your application and hosting environment allow it.

Mental Model

Think of PHP errors as letters and error_log as the delivery address.

  • log_errors = On means, “Send the letters.”
  • error_log = /some/path/file.log means, “Send them to this mailbox.”
  • An empty or host-controlled address means the letters may go to the building's central mailroom: Apache, FastCGI, or a cPanel-managed log.
  • display_errors is different: it is like showing a copy of the letter to a visitor standing at the front desk. That can help during local development, but it should normally be off on a public website.
Take Quiz

Syntax and Examples

The relevant php.ini directives are:

; Record PHP errors in a log
log_errors = On

; Do not expose error details to website visitors in production
display_errors = Off

; Write errors to a location writable by this hosting account
error_log = "/home/ACCOUNT/logs/php-errors.log"

Replace ACCOUNT with the actual hosting account name and choose a directory that exists and is writable by the PHP process. A directory outside public_html is preferable so visitors cannot download the log through the web server.

To see the settings PHP is using for the current web request, create a temporary diagnostic file:

<?php
phpinfo();

Open it in the browser and search the output for:

  • Loaded Configuration File — the main php.ini PHP loaded.
  • Scan this dir for additional .ini files and Additional .ini files parsed — extra configuration files that can override values.
  • log_errors — whether logging is enabled.
  • error_log — the configured destination.

Delete the phpinfo() file after checking it. It can reveal server paths, extensions, and configuration information.

You can also inspect the effective values without displaying the full PHP configuration:

<?php
header('Content-Type: text/plain');
echo 'log_errors: ' . ini_get('log_errors') . "\n";
echo 'error_log: ' . ini_get('error_log') . "\n";

This reports what PHP sees for that request. It does not guarantee that the path is writable or that the host has not redirected logging at a lower level.

Step by Step Execution

Use this temporary script to test a configured log destination:

<?php
header('Content-Type: text/plain');

$logFile = ini_get('error_log');
echo 'Configured error_log: ' . $logFile . "\n";

error_log('PHP log test created at ' . date('c'));
echo 'A test message was sent to PHP error logging.';

Step by step:

  1. ini_get('error_log') reads the active error_log setting for this web request.
  2. The script prints the configured value so you know which destination PHP reports.
  3. error_log(...) asks PHP to write one message using its normal error-logging destination.
  4. Check the path reported by the script, or check the error-log viewer supplied by cPanel.
  5. Remove this test script when finished. Do not leave diagnostic files accessible on a production site.

If the reported value is empty, PHP may be relying on the web server or host's default error log. Check cPanel's Errors page or ask the host which log receives FastCGI PHP errors for the account.

Real World Use Cases

PHP error logs are useful whenever an error occurs outside your browser or must be investigated after the fact.

  • Production troubleshooting: Find a fatal error causing a blank page or HTTP 500 response without showing details to visitors.
  • Form and API failures: Record exceptions, malformed input, or failed calls to a payment, email, or external API.
  • Scheduled jobs: Diagnose cron scripts that run without an interactive browser.
  • Deployment checks: Identify missing files, permissions problems, or configuration differences after publishing a new release.
  • Shared hosting support requests: Provide the exact timestamp and error message to the hosting provider when the handler or server configuration is involved.

Logs can contain file paths, request data, and sometimes sensitive information. Treat them as private operational data.

Take Quiz

Real Codebase Usage

In a real PHP project, developers usually let the platform define where logs go in production, then use PHP's normal logging facilities rather than scattering ad hoc output across the application.

A simple validation and logging pattern in older PHP code looks like this:

<?php
function loadUser($userId) {
    if (!is_numeric($userId)) {
        error_log('loadUser received an invalid user ID');
        return false;
    }

    // Query the database here.
    return true;
}

This is a guard clause: invalid input is handled early, an operational message is recorded, and the function stops before doing unsafe or unnecessary work.

For production configuration, common practices are:

  • Keep display_errors = Off so visitors do not see internals.
  • Keep log_errors = On so maintainers can diagnose failures.
  • Use a log directory outside the public web root where possible.
  • Ensure the log file is writable by the correct PHP/FastCGI user, not writable by everyone.
  • Use cPanel's log viewer when the provider manages logs centrally.
  • Ask the host which php.ini scope is active if an edited setting does not take effect.

Modern applications often use a logging library for levels and structured context, but PHP's error_log() remains useful for simple diagnostics and startup failures.

Common Mistakes

Assuming every server uses error_log in the site directory

Some hosts create files such as public_html/error_log, but this is a hosting convention, not a PHP rule. The active error_log setting and cPanel's error viewer are more reliable starting points.

Confusing displayed errors with logged errors

This configuration may show errors in the browser but not record them:

display_errors = On
log_errors = Off

For a public site, prefer:

display_errors = Off
log_errors = On

Editing a php.ini file that PHP does not load

A shared host can use a main server php.ini, per-directory configuration, generated settings, or additional .ini files. Confirm the active values with phpinfo() or ini_get() before assuming your edit worked.

Using a relative log path

This can be unclear because the working directory may differ between web requests and cron jobs:

; Avoid relying on this
error_log = "error_log"

Use an absolute path instead:

error_log = "/home/account/logs/php-errors.log"

Placing a log inside a public directory

A file under public_html may be exposed if the web server is misconfigured. Put logs outside the document root whenever possible.

Using @ to suppress errors

$result = @file_get_contents($file);

The @ operator hides useful signals and makes debugging harder. Validate inputs, handle failures deliberately, and log meaningful context instead.

Leaving phpinfo() publicly accessible

phpinfo() is useful briefly, but its output can disclose server details. Delete the file immediately after diagnosing configuration.

Comparisons

Setting or toolMain purposeSuitable for production?
log_errorsEnables or disables PHP error loggingYes; normally On
error_logChooses PHP's log destinationYes, if the path is private and writable
display_errorsSends error details to the browser responseUsually no; normally Off
error_log() functionWrites an application diagnostic message through PHP loggingYes, with safe messages
cPanel Errors viewerDisplays log entries made available by the hosting providerYes; useful on shared hosting
Apache error logRecords web-server and sometimes PHP/FastCGI-related errorsOften host-managed on shared hosting

phpinfo() and ini_get() answer different questions:

ToolBest use
phpinfo()Finding loaded configuration files and reviewing many effective settings
ini_get('error_log')Checking one active setting from the same kind of PHP request as the application

A command-line PHP process can load a different configuration from FastCGI PHP. Check through a browser when diagnosing a website request.

Take Quiz

Cheat Sheet

; Recommended production baseline
log_errors = On
display_errors = Off
error_log = "/home/ACCOUNT/logs/php-errors.log"
<?php
// Read effective settings for this request
ini_get('log_errors');
ini_get('error_log');

// Send a diagnostic message to PHP's configured log
error_log('Import job started');
  • PHP has no universal default log file path.
  • error_log identifies the configured destination; it can be empty or host-managed.
  • Apache + FastCGI + cPanel can route PHP errors to an Apache, FastCGI, or cPanel-managed log.
  • Use phpinfo() temporarily to identify loaded configuration and active settings.
  • On shared hosting, check cPanel Errors and then ask the provider if the destination is unclear.
  • Use an absolute path for a custom file.
  • Keep logs outside public_html when possible.
  • A setting can fail to work if the path is not writable or the host disallows the directive.
  • Do not enable display_errors on a public production site.

FAQ

Where is the PHP error log located on cPanel hosting?

There is no single cPanel path. First check cPanel's Errors page. Then inspect the active error_log value with phpinfo() or ini_get('error_log'). Your hosting provider may manage the underlying file location.

Does PHP always create an error_log file in public_html?

No. Some hosts do, but PHP does not require it. PHP may write to a configured private file, an Apache/FastCGI log, or another provider-managed destination.

What does an empty error_log setting mean?

It commonly means no explicit PHP file path is configured for that request. PHP may use the server's error-log configuration. Ask the host where FastCGI PHP errors are sent if cPanel does not show them.

Why did changing php.ini not change my PHP error log?

The file may not be loaded by the FastCGI handler, another configuration file may override it, the directive may be restricted, or the chosen directory may not be writable. Verify the effective value through a browser request.

Can I set the log path in PHP code?

Some installations allow ini_set('error_log', '/path/file.log'), but shared hosts may restrict it and it only affects the current process/request context. Prefer the hosting-approved configuration method for a consistent production setup.

Should I turn on display_errors to debug a live site?

Usually no. Error output can reveal paths, queries, and implementation details to visitors. Keep logging enabled and read the private log instead.

Why is my custom log file empty?

Check that log_errors is enabled, the active error_log setting matches your file, the directory exists, and the FastCGI PHP user can write to it. Also confirm you are looking at the web PHP configuration, not only the CLI configuration.

Is PHP 5.2.16 still safe to use?

No. PHP 5.2 is end-of-life and does not receive security updates. Plan an upgrade to a supported PHP release after testing application compatibility.

Take Quiz

Mini Project

Description

Create a small PHP diagnostics page that reports the active PHP logging settings and writes one controlled test entry. This is useful when a shared host makes the actual log location unclear.

Goal

Confirm whether PHP logging is enabled, discover the configured destination, and verify that PHP can send a test log message.

Requirements

Create a browser-accessible PHP script that prints plain text output. Read and display the active log_errors, display_errors, and error_log settings. Write one timestamped test message using error_log(). Avoid printing full phpinfo() output. Remove the script after testing on a production site.

Take Quiz

Keep learning

Related questions

View more