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_errorsdecides whether PHP writes errors to a log destination.error_logspecifies that destination when PHP is configured to use a file or another supported target.display_errorscontrols 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 = Onmeans, “Send the letters.”error_log = /some/path/file.logmeans, “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_errorsis 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.
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.iniPHP 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.
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:
ini_get('error_log')reads the activeerror_logsetting for this web request.- The script prints the configured value so you know which destination PHP reports.
error_log(...)asks PHP to write one message using its normal error-logging destination.- Check the path reported by the script, or check the error-log viewer supplied by cPanel.
- 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.
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 = Offso visitors do not see internals. - Keep
log_errors = Onso 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.iniscope 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 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:
Comparisons
| Setting or tool | Main purpose | Suitable for production? |
|---|---|---|
log_errors | Enables or disables PHP error logging | Yes; normally On |
error_log | Chooses PHP's log destination | Yes, if the path is private and writable |
display_errors | Sends error details to the browser response | Usually no; normally Off |
error_log() function | Writes an application diagnostic message through PHP logging | Yes, with safe messages |
| cPanel Errors viewer | Displays log entries made available by the hosting provider | Yes; useful on shared hosting |
| Apache error log |
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_logidentifies 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_htmlwhen possible. - A setting can fail to work if the path is not writable or the host disallows the directive.
- Do not enable
display_errorson 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?
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.
Keep learning
Related questions
Are PDO Prepared Statements Enough to Prevent SQL Injection in PHP?
Learn how PDO prepared statements prevent SQL injection in PHP, what they protect, and the mistakes that still leave MySQL apps vulnerable.
Can You Bind an Array to an IN Clause in PHP PDO?
Learn how PDO handles placeholders in IN() clauses, why arrays cannot be bound directly, and the safe PHP pattern to build dynamic queries.
Choosing the Right MySQL Collation for PHP and UTF-8
Learn how MySQL character sets and collations work with PHP, and how to choose a practical UTF-8 setup for web applications.