This is an old revision of the document!


Understanding 500 Internal Server Error

The 500 status code, or Internal Server Error, means that server cannot process the request for an unknown reason. Sometimes this code will appear when more specific 5xx errors are more appropriate.

This most common cause for this error is server misconfiguration (e.g. a malformed .htaccess file) or missing packages (e.g. trying to execute a PHP file without PHP installed properly), permission or ownership changes, Improperly configured php.ini, a PHP upgrade …etc, anything can trigger a 500 error in a website. The impact of the error can vary based on the cause that triggered it.

500 error is not a LiteSpeed web server specific error. If you use a control panel like cpanel, you can try the same steps with apache. Most likely Apache will return the same 500 error as LSWS. You will need to find out the reason which causes the problem. If it does not happen to apache server but only on LSWS, you can log a ticket with us for further investigation.

To troubleshoote 500 error, first to check whether the error affects just one site or every site in the server. Depending on the impact of the error, we debug further. If only one domain it affected, it can be pin-pointed to the specific script error or permission issues. If multiple domains show 500 error, it could be due to some server wide setting change or update.

You can check server error_log , stderr.log or PHP error-log(normally located where the PHP script running) to see if there is any hint of the error. During the troubleshooting, you may want to ensure PHP error reporting is on in php.ini. Please reverse them back when you done with debuging.

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT  ->   error_reporting = E_ALL
display_errors = Off -> display_errors = On
display_startup_errors = Off -> display_startup_errors = On

Please be aware that not all 500 errors log into the logs and it is common that you don’t see any hint in log files, which will make the troubleshooting more difficult then you expected.

This will list some of the common reasons/examples, which may help you during the troubleshooting processes.

Permission or ownership changes may cause 500 error. For example, to enable LiteMage extension to your Magento installation through ssh, you will need to run as user. However, if you run command incorrectly as the root user, Magento front end may return 500 instantly. The fix is to reverse file ownership and permission back to the original.

There is a huge range of things .htaccess can do and isn't difficult to use, however, if you do not enter the syntax correctly it can result in a Server 500 Error. For example,

RewriteRule ^(.*) http://www.example.com/$1 [P]  <- wrong , will bring site to 500 error

changed to RewriteRule (.*) http://www.example.com/$1 [R=301,L] ← will fix the issue To confirm whether a misconfiguration .htaccess is the cause of the 500 Internal Server error, either remove or rename the .htaccess file temporarily and then try to reload the page.

Improperly configured php.ini may lead to 500 error. For example, set the following in php.ini open_basedir = “/path/to/folder” However /path/to/folder directory does not exist at all in the system, it will cause 500 error.

Bad php code will bring website to 500 immediately. For example, right syntax should be like:

 $this->getResponse()->setRedirect(Mage::getBaseUrl()) ;

If “$” is removed somehow:

  this->getResponse()->setRedirect(Mage::getBaseUrl()) ;

It will bring website to 500 immediately. This is only one of the examples. Many times, wrong syntax PHP error will lead to 500 error.

On Plesk, PHP handler not set , prompt 500 error

When using CloudLinux, If the site is limited by memory or number of processes limits, then the user may receive 500 errors that server cannot execute the script. https://docs.cloudlinux.com/index.html?lve.html

Sometimes PHP upgrade with bug may cause 500 error.

unsupport php version by the site/theme/plugin/module may lead to 500 error.

If your PHP script makes external network connections, the connections may time out. If too many connections are attempted and time out, this will cause a “500 Internal Server Error.” To prevent these time outs and errors, you'll want to make sure that PHP scripts be coded with some timeout rules. Typically, however, catching a timeout error when connecting to a database or externally to remote resources are difficult. They, in effect, freeze the script from continuing to run.

If it is a web page ending in .cgi or .pl that is producing the error, check your script for errors.

check stderr, tail /var/log/httpd/stderr.log

2016-03-01 12:07:03.573 [STDERR] Tue Mar 1 12:07:03 2016 (12700): Fatal Error Unable to allocate shared memory segment of 134217728 bytes: shmat: Cannot allocate memory (12)

Further check phpinfo page and memory limit was set to “128M” only. While opcode cache sonsution is “128M”.

Which leads to 500 error.

Increate php memory limit from “128M” to 1024M” then fix the issue.

If too many processes in the server queue, it could exceed resources and lead to 500 error.

When php open_basedir enabled, it may lead to 500 error. Try to turn off open_basedir for that domain to see how it is going.

The following error log captured with openlitespeed when PHP open_basedir intentionally set to a non-exist folder /111, phpinfo page returns 500 error.

2018-05-16 10:59:51.391153 [NOTICE] [192.168.0.198:14271] [STDERR] PHP Warning:  Unknown: open_basedir restriction in effect. File(/usr/local/lsws/Example/html/phpinfo.php) is not within the allowed path(s): (/111) in Unknown on line 0
2018-05-16 10:59:51.391251 [NOTICE] [192.168.0.198:14271] [STDERR] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0
2018-05-16 10:59:51.391263 [NOTICE] [192.168.0.198:14271] [STDERR] PHP Fatal error:  Unknown: Failed opening required '/usr/local/lsws/Example/html/phpinfo.php' (include_path='.:/usr/local/lib/php') in Unknown on line 0

On a cpanel/WHM environment, apache runs as SuEXEC , however LSWS doesn’t.

2016-03-10 15:39:45.601 [NOTICE] [173.245.52.237:51548] [STDERR] PHP Warning: require_once(/home/demowebsites/public_html/goodmail/wp-config.php): failed to open stream: Permission denied in /home/demowebsites/public_html/goodmail/wp-load.php on line 37 2016-03-10 15:39:45.601 [NOTICE] [173.245.52.237:51548] [STDERR] PHP Fatal error: require_once(): Failed opening required '/home/demowebsites/public_html/goodmail/wp-config.php' (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/demowebsites/public_html/goodmail/wp-load.php on line 37

Need to keep LSWS to the same setting to apache. Enabled LSWS PHP SuEXEC and fixed the issue.

Check error.log, it shows: “Failed to obtain or reinitialize VMemBuf. possibly running out of swap space” and return 500 error. Relocating LSWS swap directory to a partition with enough space will fix the issue.

Install prestashop but 500 returns in Chrome. Check error log and it shows php70-json package missing. Install the missing packages and 500 is gone.

A wordpress site returned 500 error when using go2pay, but there is no hint in server error_log, stderr.log or PHP error_log. Upgrading php version and adding opcode cache module fix the issue. Some applications or plugins may need opcode cache to run.

Then run magento, it returns 500 error and show module conflicting

a:5:{i:0;s:54:“Mage registry key “umm_top_menu_exists” already exists”;i:1;s:4439:”#0 /home/yourhome/public_html/app/Mage.php(223): Mage::throwException('Mage registry k…') #1 /home/yourhome/public_html/app/design/frontend/ultimo/default/template/infortis/ultramegamenu/mainmenu.phtml(54): Mage::register('umm_top_menu_ex…', true) #2 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/furnishyo…') #3 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template→fetchView('frontend/ultimo…') #4 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template→renderView() #5 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Template→_toHtml() #6 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract→toHtml() #7 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Abstract.php(923): Mage_Core_Block_Text_List→_toHtml() #8 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Abstract.php(641): Mage_Core_Block_Abstract→toHtml() #9 /home/yourhome/public_html/app/code/core/Mage/Core/Block/Abstract.php(585): Mage_Core_Block_Abstract→_getChildHtml('topMenu', true)

When disabling extendare_EWCore.xml by changing from “True” to “false, it shows 500 error. Remove magento cache files and fix the problem.

rm -rf var/cache/*

Add java script to a wordpress plugin, but it causes 500 error. Enable LSWS debug logging and found:

2018-05-12 04:13:16.673307 [NOTICE] [47.22.54.182:54823#APVH_latampolitics.carinsurancegeorgia.org] mod_security rule [Id '2000145'] triggered! [Sat May 12 04:13:16 2018] [error] [client 47.22.54.182] ModSecurity: Access denied with code 500, [Rule: 'REQUEST_URI|REQUEST_BODY' '<space:(script|about|applet|activex|chrome) >.(script|about|applet|activex|chrome)space: >'] [id “2000145”] [rev “1”] [msg “xss”] [severity “CRITICAL”]

Mod_security rule leads to 500 error. Try to disable that mod security rule and fix the issue.

If your site is being hacked, it may trigger 500 error.

  • Admin
  • Last modified: 2018/05/16 15:10
  • by Jackson Zhang