How to configure PHP error logs in cPanel shared hosting accounts
Learn how to enable, disable, and rotate PHP error logging for your cPanel accounts. This guide covers setting error levels, log paths, and rotation limits using WHM and cPanel interfaces.
Enable or disable PHP error logging and configure error reporting levels for your shared hosting accounts. This guide targets cPanel/WHM environments running PHP 8.3.x and Apache 2.4.62.
Prerequisites
- Access to WHM as root or a reseller with sufficient privileges.
- Access to cPanel as a user (for individual account configuration).
- Knowledge of your server's PHP version (e.g., 8.3.x).
- Root shell access to manually edit Apache or PHP configuration files if needed.
Step 1: Locate the global PHP configuration directory
Before changing settings, you must identify where the PHP configuration files are stored on your server. In most cPanel installations, the global configuration resides in /etc/php or /etc/opt/remix/php. Use the following command to list the directory contents:
ls -la /etc/php/
You will see directories for different versions like 8.3. Inside these directories, look for cli and apache2 folders. The Apache configuration usually resides in /etc/php/8.3/apache2/php.ini.
Step 2: Enable PHP error logging in cPanel
For individual accounts, the easiest way to enable logging is through the cPanel interface. Log in as the user whose errors you want to track. Navigate to the Advanced PHP section in the cPanel sidebar. Click on Advanced PHP.
Scroll down to the Error Logging section. Ensure the Enable Error Logging checkbox is checked. Set the Error Reporting Level to Development or Production depending on your needs. For production shared hosting, Production is recommended to avoid leaking sensitive stack traces. Click Save.
Alternatively, use WHM to set this for all accounts. In WHM, go to Software → Manage Software → cPanel/WHM Software. Search for PHP Selector. Install the latest version if not present. Then go to Server Features → Configure PHP Selector. Select Enable Error Logging and set the default level to Production. Save changes.
Step 3: Configure error log path and rotation in WHM
By default, cPanel manages log rotation via the error_log directive in Apache. To customize the path or rotation frequency, edit the Apache configuration. In WHM, navigate to Server Features → Apache Configuration. Click Save to open the file in your browser.
Find the php_admin_value error_log directive. Change the path to a writable location like /var/log/php_errors. Add the following lines to enable rotation every 7 days with a maximum size of 5MB:
php_admin_value error_log /var/log/php_errors/php_errors.log
php_admin_flag error_log on
php_value error_reporting E_ALL & ~E_DEPRECATED & ~E_STRICT
Save the file. The error log path must be owned by the Apache user. Run this command to set permissions:
chown apache:apache /var/log/php_errors
chmod 755 /var/log/php_errors
Step 4: Set error log path for CLI scripts
Shared hosting accounts often run CLI scripts (like WordPress cron jobs). These use a different configuration file. In WHM, go to Server Features → Configure PHP Selector. Scroll to CLI Configuration. Set the Error Logging option to Yes. Specify the path /var/log/php_errors/cli_errors.log. Save changes.
Ensure the directory exists and has correct permissions:
mkdir -p /var/log/php_errors
touch /var/log/php_errors/cli_errors.log
chown apache:apache /var/log/php_errors/cli_errors.log
Verify the installation
Trigger an error to confirm logging is active. Create a test file at /home/username/public_html/test.php with this content:
Access http://yourdomain.com/test.php in a browser. Check the error log file at /var/log/php_errors/php_errors.log. You should see the test error message. If the file is empty, verify the error_log path and permissions. Ensure the Apache service restarted after changes:
systemctl restart httpd
Troubleshooting
If errors do not appear in the log, check the Apache error log first. It may be capturing PHP errors before they reach the PHP-specific log. Look at /var/log/httpd/error_log for messages like [error] PHP message : Fatal error. This indicates PHP errors are being logged to Apache instead of a dedicated file. To fix, ensure the error_log directive in php.ini is set correctly.
Another common issue is incorrect file permissions. The Apache user (usually apache or www-data) must own the log file. Run this to correct ownership:
chown -R apache:apache /var/log/php_errors
Ensure the log directory is not full. If the disk is full, rotation fails silently. Monitor disk usage with df -h. If rotation is disabled, increase the max size or frequency. Edit the logrotate configuration for PHP errors at /etc/logrotate.d/php_errors. Add this line to rotate logs daily:
/var/log/php_errors/*.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 0640 apache apache
}
Restart the logrotate service to apply changes:
systemctl restart logrotate
If you are using a custom PHP version (e.g., via php-fpm), ensure the error_log path points to a writable directory for that specific PHP pool. Check the pool.conf file in /etc/php-fpm.d for the correct error_log setting.
Finally, verify that no security module is blocking log writes. Check auditd or selinux logs if errors occur. Run ausearch -m avc -ts recent to see denied writes. If SELinux is enforcing, run setsebool -P httpd_can_write_log 1 to allow logging.