What Is a 500 Error and Why Does It Occur?
The 500 Internal Server Error is one of the most common HTTP errors, indicating that the server has encountered an internal issue but cannot display the exact details to the browser. This error can stem from various problems: from a corrupted .htaccess file to insufficient PHP memory or incorrect file permissions. Unlike 404 or 403 errors, resolving a 500 error requires systematic investigation.
In this article, we provide a step-by-step path for troubleshooting and resolving this error. Whether your site runs on shared hosting, VPS, or a dedicated server, the following steps apply to almost all environments. If you use hosting services, companies like ServerNet offer suitable management tools for accessing logs and PHP settings.
Step One: Check the Error Log
The most important tool for resolving a 500 error is the server error log. Without viewing the log, it's like searching for a needle in the dark. Depending on your hosting environment, logs are stored in different locations.
Accessing Logs in cPanel
If you use cPanel:
- Go to the Error Log section under Metrics.
- Review the latest errors. Typically, PHP or Apache errors are recorded with timestamps.
- Look for errors containing
PHP Fatal errororInternal Server Error.
Accessing Logs on Linux Servers (SSH)
If you have SSH access to the server, you can check logs with the following commands:
# Apache log (on Debian/Ubuntu-based distributions)
tail -100 /var/log/apache2/error.log
# Apache log (on RHEL/CentOS-based distributions)
tail -100 /var/log/httpd/error_log
# Nginx log
tail -100 /var/log/nginx/error.log
The tail -100 command shows the last 100 lines of the log. If there are many errors, you can use grep to filter:
grep "500" /var/log/apache2/error.log | tail -20
Enabling PHP Error Display (Temporary)
Sometimes the server log is empty or inaccessible. In such cases, you can see errors in the browser by adding the following code to the wp-config.php file (in WordPress) or the main application file:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Important Note: Do this only temporarily and remove the code after fixing the error, as displaying errors in a production environment is a security risk.
Step Two: Check the .htaccess File
The .htaccess file is one of the most common causes of a 500 error. A small typo in rewrite rules or unauthorized directives can crash the server.
Test by Temporarily Disabling htaccess
The simplest way to diagnose this is to temporarily rename the .htaccess file:
- Go to the site root (public_html) via FTP or cPanel File Manager.
- Rename the
.htaccessfile to.htaccess_old. - Reload the site. If the error is resolved, the issue is with htaccess.
If the site works, you can create a new, clean .htaccess file. For WordPress, use the following default content:
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Common Mistake: Unauthorized Directives in htaccess
Some Apache directives like php_value or php_flag are only allowed in the httpd.conf or vhost file and cause a 500 error in htaccess. If you have used PHP directives in htaccess, move them to the php.ini or user.ini file.
Step Three: Check File and Folder Permissions
Incorrect permissions are another common cause of a 500 error. If PHP cannot read or write a file, an internal error occurs.
Standard Permissions
- Files:
644(rw-r--r--) - Folders:
755(rwxr-xr-x) - Executable files like
wp-config.php:600or640
To fix permissions via SSH, use the following commands:
# Fix file permissions to 644
find /path/to/site -type f -exec chmod 644 {} \;
# Fix folder permissions to 755
find /path/to/site -type d -exec chmod 755 {} \;
If using FTP, in software like FileZilla, you can right-click on files and select File Permissions to change permissions.
File Ownership
Sometimes permissions are correct but file ownership is wrong. On shared hosting, the user nobody or www-data should typically own the files. If you have SSH access:
chown -R www-data:www-data /path/to/site
Note: The username and group may differ across distributions (e.g., apache on CentOS).
Step Four: Check PHP Memory Limit
Insufficient PHP memory (memory limit) is a hidden cause of a 500 error. When a PHP script consumes more memory than allowed, the server returns an internal error.
Increase PHP Memory in wp-config.php (WordPress)
If using WordPress, add the following line to the wp-config.php file:
define('WP_MEMORY_LIMIT', '256M');
This increases the PHP memory limit for WordPress to 256 MB. The default value is usually 40M or 64M.
Increase Memory in php.ini
If you have access to the php.ini file, change the following value:
memory_limit = 256M
On shared hosting, you can usually change this via cPanel under the MultiPHP INI Editor section.
Check Memory Usage with a Simple Code
To test if the issue is memory-related, create a simple PHP file with the following content and run it:
<?php
echo 'Memory limit: ' . ini_get('memory_limit');
?>
If this file runs without errors, the problem likely lies elsewhere.
Step Five: Troubleshoot Plugins and Themes (in WordPress)
If your site is WordPress and the above steps didn't work, a corrupted plugin or theme might be causing the 500 error.
Disable All Plugins
The simplest way is to temporarily rename the wp-content/plugins folder via FTP or File Manager:
- Go to the
wp-contentfolder. - Rename the
pluginsfolder toplugins_old. - Check the site. If the error is resolved, create a new
pluginsfolder and activate plugins one by one to find the problematic one.
Switch to a Default Theme
If the issue is with the theme, go to the wp-content/themes folder via FTP and rename the current theme's folder. WordPress will automatically revert to the default theme (e.g., Twenty Twenty-Four).
Step Six: Check Server Resources
Sometimes a 500 error occurs due to insufficient server resources (RAM or CPU). This issue is more common on shared hosting with limited resources.
Check Resource Usage in cPanel
In cPanel, go to the Resource Usage section and see if you are nearing your limits. If RAM or CPU usage consistently reaches 100%, you should either optimize heavy scripts or upgrade your hosting plan.
Check with the top Command (SSH)
If you have SSH access to the server, run the top command to see which processes are consuming the most resources:
top -b -n 1 | head -20
If a PHP process consistently has high usage, there may be a malicious script or an infinite loop in your code.
Conclusion and Summary
Resolving a 500 error typically requires patience and systematic investigation. Our recommended path in order of priority:
- Check the error log (most important step)
- Check the
.htaccessfile - Check file permissions
- Check PHP memory limit
- Troubleshoot plugins and themes (in WordPress)
- Check server resources
If the error persists after all these steps, the issue may be related to server settings or Apache/Nginx modules, requiring intervention from the hosting support team. In that case, provide the error log to support to speed up the resolution process.
Remember to always back up important files (like .htaccess and wp-config.php) before making any changes. This will save you from potential headaches.
Comments 0
No comments yet — be the first!