Fixing the '500 Internal Server Error' message while running PHP
A 500 Internal Server Error indicates that something went wrong on the server while executing a PHP script. On ruachost.com, this error is often caused by incorrect file permissions or invalid directives in .htaccess.
Common Causes
Section titled “Common Causes”1. File and Directory Permissions
Section titled “1. File and Directory Permissions”-
PHP scripts may fail if permissions are set incorrectly.
-
Typical errors include:
SoftException in Application.cpp: UID of script is smaller than min_uidMismatch between target UID and UID of fileFile is writeable by others
-
Directories should be set to
755. -
Files should be set to
644. -
Example commands:
cd public_htmlfind . -type d -exec chmod -c 755 {} \;find . -type f -exec chmod -c 644 {} \; -
Do not change permissions on the
public_htmldirectory itself.
2. Invalid .htaccess Directives
Section titled “2. Invalid .htaccess Directives”-
Servers running PHP as a CGI binary cannot use
php_flagorphp_valuedirectives in.htaccess. -
Example error:
Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration
- Move PHP directives into a custom
php.inifile. - Remove or comment out invalid directives in
.htaccess.
3. Ownership Issues
Section titled “3. Ownership Issues”- Files owned by
rootornobodyinstead of your user account can trigger errors. - Fix: Contact Ruachost Support to correct file ownership if needed.
4. Memory Limits
Section titled “4. Memory Limits”-
Scripts may exceed PHP memory limits.
-
Fix: Increase
memory_limitinphp.inior.user.ini.memory_limit = 256M
Troubleshooting Steps
Section titled “Troubleshooting Steps”-
Check error logs:
- Shared hosting: view logs in cPanel → Metrics → Errors.
- VPS/Dedicated: check
/usr/local/apache/logs/error_logor/usr/local/apache/logs/suphp_log.
-
Correct permissions using
755for directories and644for files. -
Review
.htaccessfor invalid PHP directives. -
Adjust memory limits if scripts are resource‑intensive.
-
Contact support if ownership issues persist.