Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:config:understanding_500 [2018/05/16 18:28]
Lisa Clarke Proofreading
litespeed_wiki:config:understanding_500 [2018/09/20 14:00] (current)
Lisa Clarke [PHP Code with wrong php configuration settings] Proofreading
Line 23: Line 23:
  For example, to enable the LiteMage extension in your Magento installation through SSH, you will need to run a a non-root user. However, if you run the command incorrectly as the root user, the Magento front end may return 500 instantly. The fix is to reverse file ownership and permissions back to the original user.  For example, to enable the LiteMage extension in your Magento installation through SSH, you will need to run a a non-root user. However, if you run the command incorrectly as the root user, the Magento front end may return 500 instantly. The fix is to reverse file ownership and permissions back to the original user.
  
 +===== phpinfo.php owned by root instead of user =====
 +Sometimes we need to check phpinfo page during the troubleshooting. When ssh login as root to server, go to document root and create phpinfo.php,​ the phpinfo.php file will be owned by root:root instead of user:​user. ​
 +
 +Sometimes it may return 500 error when accessing domain.com/​phpinfo.php if some restriction set there but not always. ​
 +
 +The server error may show the following:
 +[Thu Jun 07 21:​04:​36.450359 2018] [:error] [pid 3807521:tid 139749549020928] [client 77.82.94.132:​9254] SoftException in Application.cpp:​382:​ UID of script "/​home/​vivi/​public_html/​phpBB2/​info.php"​ is smaller than min_uid
 +[Thu Jun 07 21:​04:​36.450651 2018] [core:​error] [pid 3807521:tid 139749549020928] [client 77.82.94.132:​9254] End of script output before headers: info.php
 +
 +Changing the info.php to be owned by user:user will generally fix the issue. ​
 ===== Faulty .htaccess ===== ===== Faulty .htaccess =====
 There is a huge range of things ''​.htaccess''​ can do and it isn't difficult to use, however, if you do not enter the syntax correctly it can result in a Server 500 Error. ​ There is a huge range of things ''​.htaccess''​ can do and it isn't difficult to use, however, if you do not enter the syntax correctly it can result in a Server 500 Error. ​
 +
 +==== Example 1 ====
 For example, ​ For example, ​
   RewriteRule ^(.*) http://​www.example.com/​$1 [P]   RewriteRule ^(.*) http://​www.example.com/​$1 [P]
 Will cause a 500 error. But change it to Will cause a 500 error. But change it to
   RewriteRule (.*) http://​www.example.com/​$1 [R=301,L]   RewriteRule (.*) http://​www.example.com/​$1 [R=301,L]
-And that will fix the issue.+and that will fix the issue. 
 + 
 +==== Example 2 ==== 
 +<​Directory>​...</​Directory >​ can not be used in .htacess and it will cause 500 error for Apache, While LSWS will ignore the unsupported directive instead of giving 500 error. 
 + 
 +For example, the following should not be used in .htaccess. 
 +  <​Directory /​home/​user1/​public_html/​wp-admin/>​ 
 +    Deny from all 
 +  </​Directory>​ 
 + 
 +instead, you can create .htaccess under /wp-admin/ and place diretive there. 
 +  Deny from all
  
 To confirm whether a misconfiguration in ''​.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. To confirm whether a misconfiguration in ''​.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.
  
 +==== Example 3 ====
 +The following "​Alias"​ directive in .htaccess will cause 500 on Apache (LSWS will ignore it without returning 500) since "​Alias"​ directive is not allowed in .htaccess.
 +
 +  Alias "/"​ "/​home/​$USER1/​public_html/"​
 +  ​
 +==== Example 4 ====
 +Syntax is wrong for the followintg directive:
 +  Header always set Strict-Transport-Security:​ max-age=63072000;​ includeSubDomains;​ preload
 +
 +which will lead to "Too many arguments to directive"​ error in error_log:
 +
 +  [Tue Sep 11 19:​59:​40.864917 2018] [core:​alert] [pid 15738] [client 66.666.76.139:​64740] /​home/​example/​public_html/​.htaccess:​ Too many arguments to directive
 +
 +The correct syntax is the following and it should fix the 500 error for Apache:
 +  Header always set Strict-Transport-Security:​ "​max-age=63072000;​ includeSubDomains;​ preload"​
 +
 +===== Different level of Rewrite rules misplaced to the wrong level =====
 +
 +Per virtual host rewrite rules (rewrite rules in Apache virtual host configuration) and per directory rewrite rules (rewrite rules in .htaccess) are different. ​ When placing the same rules to the wrong place, it may cause 500 error.
 +
 +For example, the following works in .htaccess: ​
 +
 +  RewriteEngine On
 +  RewriteCond %{REQUEST_FILENAME} !-f
 +  RewriteRule . /index.php [L]
 +  ​
 +Putting the same thing in Apache VirtualHost config doesn’t work at all:
 +
 +  <​VirtualHost *:80>
 +    ServerName example.com
 +    DocumentRoot /​var/​www/​example/​
 +    <​Directory /​var/​www/​example/>​
 +        Allow From All
 +    </​Directory>​
 +    RewriteEngine On
 +    RewriteCond %{REQUEST_FILENAME} !-f
 +    RewriteRule . /index.php [L]
 +  </​VirtualHost>​
 +
 +Apache doesn’t tell you why it doesn’t work. It just doesn’t work. You most likely will get an Error 500 status with a message in the logs that looks like this:
 +
 +Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
 +
 +===== Incorrect Rewrite Rules misplace in differernt directories =====
 +The following rewrite rules in subfolder is incorrect and it will cause 500 for LiteSpeed.
 +/​home/​user1/​public_html/​subfolder1] vi .htaccess
 +  RewriteEngine On
 +  RewriteCond %{REQUEST_FILENAME} !-f
 +  RewriteCond %{REQUEST_FILENAME} !-d
 +  RewriteRule ^(.*)$ subfolder1/​index.php/​$1 [L]
 +
 +The correct rule should be:
 +/​home/​user1/​public_html/​subfolder1] vi .htaccess
 +  RewriteEngine On
 +  RewriteCond %{REQUEST_FILENAME} !-f
 +  RewriteCond %{REQUEST_FILENAME} !-d
 +  RewriteRule ^(.*)$ index.php/​$1 [L]
 =====  Improperly Configured php.ini ===== =====  Improperly Configured php.ini =====
 An improperly configured ''​php.ini''​ may lead to 500 error. ​ An improperly configured ''​php.ini''​ may lead to 500 error. ​
Line 50: Line 130:
 It will bring the website to 500 immediately. It will bring the website to 500 immediately.
 This is only one example. Many times, wrong PHP syntax will lead to a 500 error. This is only one example. Many times, wrong PHP syntax will lead to a 500 error.
 +
 +===== PHP Code with wrong php configuration settings =====
 +
 +Sometimes, a 500 error may be not easy to locate. If you move ''​.htaccess''​ to ''​.htaccess.bak''​ and move ''​php.ini''​ to ''​php.ini.bak'',​ and the 500 error still happens, it might mean there is something wrong in the PHP code. That can be hard to find. 
 +
 +We experienced a case with WHMCS. Someone placed an incorrect setting in ''​configuration.php'':​
 +  $display_errors = E_All;
 +
 +''​E_All''​ is an incorrect value for the PHP ''​$display_errors''​ setting. Rather, it is meant for the ''​$error_reporting''​ setting. ''​$display_errors''​ should be either ''​true''/''​false'',​ or ''​on''/''​off''​. We changed it to ''​true'',​ and that fixed the 500 error.
 +  $display_errors = true;
  
 ===== PHP Handler Not Set ===== ===== PHP Handler Not Set =====
Line 63: Line 153:
 Unsupported PHP version used by the site/​theme/​plugin/​module may lead to a 500 error. Unsupported PHP version used by the site/​theme/​plugin/​module may lead to a 500 error.
  
-===== PHP Coding Timing Out =====+===== PHP Scripts Time out =====
 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, make sure that PHP scripts are coded with some timeout rules. Typically, it's difficult to catch a timeout error when connecting to a database or remote resources, as they effectively freeze the script. 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, make sure that PHP scripts are coded with some timeout rules. Typically, it's difficult to catch a timeout error when connecting to a database or remote resources, as they effectively freeze the script.
  
Line 132: Line 222:
 ===== Hacked Site ===== ===== Hacked Site =====
 If your site is being hacked, it may trigger a 500 error. If your site is being hacked, it may trigger a 500 error.
 +
 +===== Perl script missing "​Content-Type"​ header may return 500 =====
 +
 +Run a simple "Hello World" perl script at http://​exmaple.com/​cgi-bin/​test.pl but it return 500 error.
 +
 +vi test.pl
 +<​code>​
 +  #​!/​usr/​bin/​perl
 +  print "​Hello,​ World!\n";​
 +</​code>​
 +
 +A Perl CGI script must output the header, HTML code and also must begin with a special first line. In this case, header "​Content-type"​ is missing and it is not a CGI script. Please also be aware that there is a blank line after **print "​Content-Type:​ text/​html\n\n";​**.
 +
 +the right script should be:
 +<​code>​
 +<​code>​
 +  #​!/​usr/​bin/​perl
 +  ​
 +  print "​Content-Type:​ text/​html\n\n";​
 +  ​
 +  print "​Hello,​ World!\n";​
 +</​code>​
 +You can check the example [[https://​users.cs.cf.ac.uk/​Dave.Marshall/​PERL/​node196.html|here]].
 
litespeed_wiki/config/understanding_500.1526495282.txt.gz · Last modified: 2018/05/16 18:28 by Lisa Clarke