Overview
A 500 Internal Server Error happens when the webserver receives an unexpected error. If you're actively experiencing this issue you can use the following process to monitor the Apache log for new errors:
- Run tail -n0 -f /var/log/apache2/error_log
- Refresh the website the error is happening on
- Exit tail with CTRL+C and review the output
A few of the common reasons for a 500 are covered in the next section.
Common causes of 500 error
Most of the time when this occurs on a cPanel server, it's due to having invalid coding in the .htaccess file, which looks like this in the Apache error log:
[Wed May 13 06:31:26.262337 2020] [core:alert] [pid 2140] [client 10.3.17.46:57731] /home/sean/public_html/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration
In this case, the server did not have the Apache module mod_env, you can avoid causing a fatal error in this situation by using the IfModule statement in the .htaccess file:
<IfModule mod_env>
SetEnv test test
</IfModule>
If the server does not have enough memory to allocate to the request:
[Fri May 08 00:42:01.220008 2020] [cgi:error] [pid 24686] (12)Cannot allocate memory: [client 10.3.17.46:31164] AH01223: couldn't spawn child process: /usr/local/cpanel/cgi-sys/wredirect.cgi
If a user has a limit on the number of inodes it can use in CloudLinux this could also cause a 500 error if the script is unable to create the files it needs, this will return more of a generic 500 error. You can check the quota of the user using the quota command:
# test root@93545571 /home/testuser/public_html]cPs# quota -su testuser
Disk quotas for user an000282 (uid 1282):
Filesystem space quota limit grace files quota limit grace
/dev/sda2 4239M 0K 0K 323k* 300k 360k none
In this example the test user has exceeded the number of files it can create, this resulted in a 500 error reported by Apache due to a bad file descriptor:
[Sat Aug 01 08:26:22.459080 2020] [:error] [pid 28368:tid 47803753387776] [client xxx.xx.xxx.x:36561] Sat Aug 1 08:26:22 2020 (18854):
[Sat Aug 01 08:26:22.459189 2020] [:error] [pid 28368:tid 47803753387776] [client xxx.xx.xxx.x:36561] Fatal Error
[Sat Aug 01 08:26:22.459311 2020] [:error] [pid 28368:tid 47803753387776] [client xxx.xx.xxx.x:36561] Unable to create lock file: Bad file descriptor (9)
[Sat Aug 01 08:26:22.459354 2020] [:error] [pid 28368:tid 47803753387776] [client xxx.xx.xxx.x:36561]
[Sat Aug 01 08:26:22.460977 2020] [core:error] [pid 28368:tid 47803753387776] [client xxx.xx.xxx.x:36561] End of script output before headers: index.php
Another cause of a 500 error is related to there being an issue with PHP, steps relating to troubleshooting can be found here:
(HTTP ERROR 500) PHP website blank or showing a white page. Internal Server Error