How to debug 500 Internal Server Error in cPanel Shared Hosting
Fix 500 errors on cPanel shared hosting by checking error logs, validating .htaccess syntax, and reviewing PHP configurations.
Follow these steps to resolve a 500 Internal Server Error on a cPanel shared hosting account. These instructions target cPanel 118.x running on Apache or OpenLiteSpeed environments.
Prerequisites
- Access to the cPanel interface as the account owner or reseller.
- SSH access to the server root if you need to inspect system logs.
- Basic knowledge of Linux file permissions and Apache configuration.
- Knowledge of PHP error reporting settings.
Step 1: Check the main Apache error log
Identify the specific error message causing the failure by viewing the main server error log. Open the terminal and run the following command to find the most recent error entry. Look for lines containing your domain name or "AH00124" which indicates a server configuration error.
sudo tail -n 50 /var/log/httpd/error_log
[Tue Nov 12 10:00:01.000000 2024] [core:error] [pid 12345] (2)No such file or directory: AH02268: The requested path was not found on the disk.
AH00126: Configuration syntax error noted: AH00526: Syntax error on line 1 of /var/www/html/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or not supported by this server.
If the log shows a syntax error, proceed to Step 2. If it shows a permission error, check the file ownership in Step 3.
Step 2: Validate .htaccess syntax
A 500 error is frequently caused by a malformed .htaccess file. Navigate to your website's root directory via the terminal. Locate the .htaccess file and rename it to .htaccess.bak to temporarily disable it. This forces Apache to ignore custom rules and serve the default content.
cd /home/username/public_html
mv .htaccess .htaccess.bak
Refresh your website in the browser. If the site loads normally, the issue resides in the .htaccess file. Restore the original file to examine the contents carefully.
mv .htaccess.bak .htaccess
Alternatively, use cPanel's File Manager to locate the file. Right-click the .htaccess file and select "Edit". Ensure there are no syntax errors such as missing spaces, incorrect directives, or unsupported modules.
Step 3: Check PHP error logs
If Apache logs are clean, the error may originate from a PHP script. Enable display of errors to see the specific PHP fatal error. Open the php.ini file located in the public_html directory. Change the error reporting settings to show all errors.
php_flag display_errors On
php_flag log_errors On
Save the file and refresh the page. Check the error_log file in the /var/log/php-fpm/ or /var/log/nginx/error.log directory depending on your stack. Look for "Fatal error" or "Parse error" messages.
Step 4: Review database connections
A 500 error often occurs when a PHP script fails to connect to the MySQL or MariaDB database. Verify that the database credentials in the application configuration file (usually config.php or wp-config.php) are correct. Ensure the database user has the necessary privileges.
grep -i "db_password" /home/username/public_html/config.php
Check the database status in cPanel under "Databases". If the database is down or the user is locked, the script will throw a 500 error. Restart the MySQL service if the database is unresponsive.
sudo systemctl restart mariadb
Verify the installation
Confirm the fix by accessing the website URL in a browser. The page should load without the 500 error banner. Run a health check command to ensure the server responds correctly to HTTP requests.
curl -I https://yourdomain.com
HTTP/2 200
date: Tue, 12 Nov 2024 10:00:00 GMT
content-type: text/html; charset=UTF-8
Troubleshooting
Error persists: If the 500 error returns after disabling .htaccess and checking PHP logs, the issue may be with the main Apache configuration. Edit the httpd.conf or apache2.conf file to ensure no conflicting directives exist. Restart Apache to apply changes.
sudo systemctl restart httpd
Permission denied: Ensure all files in the public_html directory are owned by the user and have the correct permissions. Run the following command to set standard permissions for a shared hosting environment.
chown -R username:username /home/username/public_html
chmod -R 755 /home/username/public_html
chmod -R 750 /home/username/public_html/protected
Module missing: If the error mentions a missing module, install the required Apache module via cPanel or the terminal.
sudo a2enmod rewrite
sudo systemctl restart apache2
SSL/TLS issues: If the error occurs only on HTTPS, check the SSL certificate validity. Renew the certificate in cPanel under "SSL/TLS" if it has expired. Ensure the .htaccess file does not force HTTPS on a non-SSL server.
Resource limits: If the error occurs under high load, the server may have hit a resource limit. Check the php.ini file for memory_limit and max_execution_time. Increase these values if necessary.
php_value memory_limit 256M
php_value max_execution_time 300
PHP version mismatch: Ensure the application is compatible with the installed PHP version. If the app requires an older version, switch to the appropriate PHP version in cPanel under "Select PHP Version".
By systematically checking logs, permissions, and configurations, you can isolate and resolve the 500 Internal Server Error on cPanel shared hosting.