Fixing "Internal Server Error" (500) in Apache/Nginx
Check Server Logs for More Details
The first step in diagnosing the issue is checking the error logs.
For related server-error topics, see Error 508 — Resource Limit Reached, Increasing PHP Limits, and Fixing ERR_INVALID_RESPONSE in PHP.
Apache Error Log
sudo tail -f /var/log/apache2/error.log # Debian/Ubuntu
sudo tail -f /var/log/httpd/error_log # CentOS/RHEL
Nginx Error Log
sudo tail -f /var/log/nginx/error.log
Identify the specific cause of the error before proceeding with fixes.
Fix .htaccess Issues (For Apache)
A corrupted .htaccess file is one of the most common causes of 500 Internal Server Errors.
Rename .htaccess to Disable It
mv /home/user/public_html/.htaccess /home/user/public_html/.htaccess_backup
Restart Apache
sudo systemctl restart apache2
Regenerate .htaccess (For WordPress)
If your site is WordPress-based:
- Go to WordPress Admin > Settings > Permalinks
- Click Save Changes to regenerate .htaccess.
- If the issue is resolved, update .htaccess manually and check for syntax errors.
Check PHP Configuration & Errors
If the error is PHP-related, check the PHP logs.
Enable Debugging in wp-config.php (For WordPress)
Edit the wp-config.php file:
nano /home/user/public_html/wp-config.php
Add or update:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);
Error logs will be stored in wp-content/debug.log.
Check PHP Error Logs
For Apache:
sudo tail -f /var/log/apache2/php_errors.log
For PHP-FPM:
sudo tail -f /var/log/php8.0-fpm.log
Fix any PHP syntax errors or missing extensions.
Check File & Folder Permissions
Incorrect permissions can prevent the server from accessing files.
Set Correct File & Directory Permissions
find /home/user/public_html -type d -exec chmod 755 {} \;
find /home/user/public_html -type f -exec chmod 644 {} \;
Set Correct Ownership
For Apache:
chown -R www-data:www-data /home/user/public_html
For Nginx:
chown -R nginx:nginx /home/user/public_html
Restart the web server after applying changes:
sudo systemctl restart apache2
sudo systemctl restart nginx
Increase PHP Limits
If your site requires more memory, increase PHP limits.
Edit php.ini
sudo nano /etc/php/8.0/apache2/php.ini # Apache
sudo nano /etc/php/8.0/fpm/php.ini # Nginx
Modify the Following Settings
memory_limit = 512M
max_execution_time = 300
upload_max_filesize = 128M
post_max_size = 128M
Restart PHP & Web Server
sudo systemctl restart php8.0-fpm
sudo systemctl restart apache2
Fix Server Configuration (Apache/Nginx)
If the error persists, the issue may be with the web server configuration.
Check Apache Config for Syntax Errors
sudo apachectl configtest
If errors appear, fix them in:
sudo nano /etc/apache2/apache2.conf
Restart Apache:
sudo systemctl restart apache2
Check Nginx Config for Syntax Errors
sudo nginx -t
If errors appear, edit:
sudo nano /etc/nginx/nginx.conf
Restart Nginx:
sudo systemctl restart nginx
Summary of Fixes
| Issue | Fix |
|---|---|
| Corrupt .htaccess file | Rename it & regenerate via WordPress |
| PHP errors | Enable debugging in wp-config.php & check logs |
| File/folder permission issues | Run chmod 755 for directories, chmod 644 for files |
| Memory limits exceeded | Increase memory_limit in php.ini |
| Apache/Nginx misconfiguration | Run apachectl configtest or nginx -t |
Now your website should work without an Internal Server Error!


