Debugging 500 Internal Server Error in cPanel Shared Hosting
Fix cPanel 500 errors by checking error logs, disabling plugins, and verifying file permissions. Follow these steps to restore site access on cPanel 118.x shared servers.
You will identify the cause of a 500 Internal Server Error and restore site functionality by checking error logs and file permissions. These steps apply to cPanel 118.x shared hosting environments running on Ubuntu, AlmaLinux, or CentOS Stream.
Prerequisites
- Access to a cPanel account with reseller or root privileges.
- Web browser with an active internet connection.
- Knowledge of basic file permissions and directory structures.
- Ability to access the cPanel interface or use SSH.
Step 1: Check the Error Log
Locate the specific error message in the error log to determine if the issue is a script error or a server configuration problem. Navigate to the error log file in the home directory of the affected domain.
cd ~/public_html
less error_log
You will see lines of text detailing the error. Look for lines containing "500 Internal Server Error" or "Internal Server Error". The log will often state the specific PHP error or Apache configuration issue causing the failure.
[Wed Oct 24 10:23:45 2024] [error] [client 192.168.1.1] PHP Fatal error: Uncaught Error: Call to undefined function in /home/user/public_html/index.php:10
Step 2: Disable All Plugins
Third-party plugins or modules often cause conflicts that trigger 500 errors. Temporarily disable all plugins to see if the site loads normally. Go to the cPanel home screen and click on the "Software" section.
Inside the Software section, find the "Plugins" icon and click it. Select the "Disable All" option if available, or manually toggle the switch next to each plugin to the "Disabled" position. Refresh the website after disabling the plugins.
If the site loads successfully, one of the disabled plugins was the culprit. Re-enable them one by one, testing the site after each action, until the error returns. Identify the specific plugin causing the conflict and contact its developer or find an alternative.
Step 3: Verify File Permissions
Incorrect file permissions prevent the web server from reading or executing scripts, resulting in a 500 error. Use the File Manager in cPanel to check the permissions of the root directory and subdirectories. Right-click on the domain folder and select "Change Permissions".
Ensure the "Directory Permissions" are set to 755 and "File Permissions" are set to 644. If you see 777 permissions, change them immediately as they are a security risk. Save the changes and refresh the browser.
chmod 755 ~/public_html
chmod 644 ~/public_html/*.php
Run these commands via SSH if you prefer the command line. Verify that the changes took effect by listing the directory contents.
ls -l
You will see output like this:
drwxr-xr-x 2 user group 4096 Oct 24 10:00 .
drwxr-xr-x 3 user group 4096 Oct 24 10:00 ..
-rw-r--r-- 1 user group 1234 Oct 24 10:00 index.php
Step 4: Check .htaccess Configuration
A malformed .htaccess file is a frequent cause of 500 errors in Apache-based environments. Rename the .htaccess file to disable it temporarily. Go to the File Manager, navigate to the public_html directory, and find the .htaccess file.
Right-click the file, select "Rename", and change the name from .htaccess to .htaccess_backup. Refresh the website. If the site works, the issue lies within the .htaccess configuration.
Edit the backup file to remove problematic directives like "RewriteEngine On" or custom mod_rewrite rules. Revert to the original .htaccess file only after fixing the syntax errors.
Verify the installation
Test the website by opening the URL in a web browser. You should see the homepage load without the 500 error. If the site still fails, check the error log again for new messages.
curl -I https://your-domain.com
The response header should return "200 OK" instead of "500 Internal Server Error".
Troubleshooting
Error Log is Empty: If the error log is empty or shows no relevant entries, the issue may be at the Apache or PHP-FPM level. Check the main Apache error log located at /var/log/httpd/error_log or /var/log/messages.
PHP Version Mismatch: Ensure the site is using the correct PHP version. In cPanel, go to "Select PHP Version" and choose the version required by your application. Restart the PHP-FPM service after changing the version.
Missing Modules: Some scripts require specific Apache modules like mod_rewrite or mod_ssl. Verify these are enabled in the "Software" section of cPanel. Enable any missing modules and restart the server.
Database Connection Failed: A 500 error can occur if the database is unreachable. Check the database status in cPanel and ensure the credentials in the application configuration are correct.
File Ownership: Ensure all files are owned by the correct user. Run the following command via SSH to fix ownership:
chown -R user:user ~/public_html
Replace "user" with your actual cPanel username. Run this command only if you are certain of the ownership structure.