500 Internal Server Error
By the end of this lesson you will know how to diagnose 500 Internal Server Error responses by checking error logs, PHP configuration, rewrite rules, and application code.
What a 500 Means
A 500 Internal Server Error means the server encountered an unexpected condition that prevented it from completing the request. Unlike 403 (access denied), this usually points to broken server-side configuration or application code.
Most Common Causes
| Cause | Category | Likelihood |
|---|---|---|
| Bad rewrite rules | Configuration | Very common |
| Broken PHP handler or socket | PHP Integration | Very common |
| PHP fatal error | Application | Common |
| File permission on scripts | Permissions | Common |
Missing .htaccess module support | Configuration | Occasional |
| Resource exhaustion | Infrastructure | Under load |
Diagnostic Steps
Step 1: Check the Error Log
# View the most recent error entries
tail -100 /usr/local/lsws/logs/error.log
# Filter for 500-related errors
grep -i "error\|failed\|fatal\|500" /usr/local/lsws/logs/error.log | tail -30
Step 2: Check PHP Errors
# Check lsphp stderr output
tail -50 /usr/local/lsws/logs/stderr.log
# Check PHP's own error log (location varies by config)
tail -50 /var/log/php8.4-fpm.log 2>/dev/null
# Check if lsphp processes are running
ps aux | grep lsphp | grep -v grep
Step 3: Test PHP Directly
Create a simple test file to isolate the problem:
# Create a PHP test file
echo '<?php phpinfo(); ?>' > /var/www/example.com/public/test.php
# Test it via curl
curl -I http://localhost/test.php
# Clean up after testing
rm /var/www/example.com/public/test.php
If test.php works but your app returns 500, the problem is in the application code or its .htaccess rules.
Step 4: Check Rewrite Rules
Bad rewrite rules are one of the most common causes of 500 errors:
# Check .htaccess for syntax issues
cat /var/www/example.com/public/.htaccess
# Common problem: rewrite loop or referencing a module not loaded
# Look for lines like:
# RewriteRule ^(.*)$ index.php/$1 [L]
# Ensure the target file actually exists
Step 5: Check External App (PHP) Socket
# Verify the socket path exists
ls -la /tmp/lshttpd/
# Check that the external app is defined correctly in WebAdmin
# Server → External App → check command, address, max connections
Quick Fix Reference
| Problem | Fix Command |
|---|---|
| PHP not running | sudo /usr/local/lsws/bin/lswsctrl restart |
| Permission on PHP scripts | chmod 644 *.php && chown nobody:nogroup *.php |
Broken .htaccess | Temporarily rename: mv .htaccess .htaccess.bak |
| Socket file missing | Restart OLS and check external app config |
| PHP memory exhausted | Increase memory_limit in php.ini |
If removing .htaccess fixes the 500 error, the problem is in the rewrite rules, not the server. Add rules back one at a time to find the culprit.
Key Takeaways
- 500 errors usually point to configuration or application problems, not web server bugs.
- The error log (
/usr/local/lsws/logs/error.log) is your primary diagnostic tool. - PHP handler issues and bad rewrite rules are the two most common causes.
- Use test files and
.htaccessisolation to narrow down the problem.
What's Next
- Continue to Permission Issues for deeper filesystem troubleshooting.