How to Fix Apache 500 Internal Server Error
Quick Fix Summary
TL;DRCheck Apache error logs immediately, then verify file permissions and syntax of .htaccess and virtual host configurations.
An Apache 500 Internal Server Error indicates the server encountered an unexpected condition preventing it from fulfilling the request. It's a generic catch-all for server-side script or configuration failures.
Diagnosis & Causes
Recovery Steps
Step 1: Locate the Exact Error in Logs
The Apache error log contains the specific reason for the 500 error. Check the main and virtual host logs.
# Check main Apache error log
tail -f /var/log/apache2/error.log
# Check specific virtual host error log (common path)
tail -f /var/log/apache2/example.com-error.log Step 2: Verify File and Directory Permissions
Apache needs read (and often execute) permissions on files and directories. The user/group (e.g., www-data) must own or have access.
# Check ownership and permissions of web root
ls -la /var/www/html/
# Recursively set correct ownership (adjust user:group)
sudo chown -R www-data:www-data /var/www/html/
# Set secure directory (755) and file (644) permissions
sudo find /var/www/html/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/ -type f -exec chmod 644 {} \; Step 3: Check .htaccess and Apache Configuration Syntax
A single typo in .htaccess or your site's virtual host configuration can cause a 500 error. Test the syntax.
# Test main Apache configuration syntax
sudo apache2ctl configtest
# Temporarily rename .htaccess to disable it for testing
sudo mv /var/www/html/.htaccess /var/www/html/.htaccess.bak Step 4: Isolate Script/Module Failures
If using PHP/Python, increase error reporting and check its specific logs. Also, ensure required Apache modules are enabled.
# Enable detailed PHP errors (add to php.ini or .user.ini)
display_errors = On
error_reporting = E_ALL
log_errors = On
error_log = /var/log/php_errors.log
# Check if crucial Apache modules are active
sudo a2enmod rewrite
sudo systemctl restart apache2 Step 5: Test with a Minimal Configuration
As a last resort, create a minimal test to rule out application code. If this works, the issue is in your app config.
# Create a simple test PHP file in your web root
echo "<?php echo 'Apache/PHP is working.'; ?>" > /var/www/html/test.php
# Create a plain HTML test file
echo '<html><body>Test HTML</body></html>' > /var/www/html/test.html Architect's Pro Tip
"For intermittent 500 errors, check `mod_security` or `mod_evasive` logs. A blocked request by the WAF often manifests as a generic 500, not a 403."
Frequently Asked Questions
The Apache error log is empty. Where else should I look?
Check the system log (`journalctl -u apache2`), PHP-FPM/Apache module-specific logs, and your application framework's logs (e.g., Laravel, Django). Also, ensure the Apache LogLevel directive is set to 'debug' or 'info' temporarily.
I fixed the error, but my browser still shows 500. What's wrong?
Your browser or a CDN is caching the error page. Force a hard refresh (Ctrl+F5 or Cmd+Shift+R) or add a query string like `?cachebust=123` to the URL to bypass the cache.