I was building a client website and after some coding work(uploading and overwriting an existing file), i suddenly started seeing a 500 Internal Server Error, though i fixed the problem, am about to write a comprehensive tutorial about, causes and how to fix it, incase someone encounter such.
A 500 internal server error do occur when a browser encounter problem with a website server. This error is cause by many things, e.g invalid permissions, invalid ownership, bad lines in your php.ini or .htaccess file, invalid requests in the script, e.t.c.
Generally, this is how the error is display
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, firstname.lastname@example.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
The 500 Internal Server Error message might be seen in any number of ways because each website is allowed to customize the message. Here are several common ways that you might see the HTTP 500 error:
- 500 Internal Server Error
- HTTP 500 – Internal Server Error
- Internal Server Error
- HTTP 500 Internal Error
- 500 Error
- HTTP Error 500
What is a 500 Internal Server Error?
Any web client (e.g. your Web
browser), goes through a process or rather a cycle when communicating with the Web server as illustrated below.
#1 Obtain an IP address from the IP name of the site (the site URL without the initial ‘http://’). This lookup (conversion of IP name to IP address) is provided by domain name servers (DNSs).
#2 Open an IP socket connection to that IP address.
Write an HTTP data stream through that socket.
#3Receive an HTTP data stream back from the Web server in response.
This data stream contains status codes, whose values are determined by the HTTP protocol, then Parse this data stream for status codes and other useful information.
500 internal error occurs in the final step above when the client receives an HTTP status code that it recognises as 500.
Causes of 500 Internal Server Error
The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the website’s server but the server could not be more specific on what the exact problem is.
The causes of this error are many, but i will outline the major three(3).
- File or Folder Permissions
if you see in your cpanel error log, something like [Sun Jun 05 12:03:22 2011] [error] [client 184.108.40.206] SoftException in Application.cpp:601: Directory “/home1/ examplec/public_html” is writeable by group, it means your account has a folder with an invalid permission set. To correct this, simply restore the permissions to from “777” to “755”.
if it is a file, chmod to “644”, or if it cgi, chmod to “755”.
- Bad code or syntaxes in your .htaccess
When using .htaccess, if you do not enter the syntax correctly it can result in a Server 500 Error. Some common examples of what could cause an error is listed below.
[Sun Jun 05 12:07:10 2011] [alert] [client 220.127.116.11] / home1/examplec/public_ html/.htaccess: Option
FollowSymlinks not allowed here In this example the error is simple to fix; in the file specified, use a permitted directive–in this case use “SymlinksIfOwnerMatches” instead of “FollowSymlinks”, or remove the line entirely.
#2 Syntax Not Closed
[Sun Jun 05 12:11:38 2011] [alert] [client 18.104.22.168] /home1/examplec/public_ html/.htaccess: /home1/examplec/public_ html/.htaccess:3:
ExampleRule/ Module>” directive properly and put the rules on their own line to resolve the problem.
You will observe syntax was not closed. Again, the solution is to simply fix the syntax, or remove it. In this case, close the ending “
There are few others that can lead to corrupt .htacess file, but it delighting to know the description given by the error message is enough to give you an idea of what is wrong and how to fix it.
- File or Folder Permissions
- Improperly configured php.ini
This could be categorised into ForceType and Php_value.
- Force Type
When you are using files with (or without) an extension different then the normal extension for that filetype you can use ForceType in your .htaccess file to make it clear to the server how to handle that file (or all the files in the folder) (this works on servers without phpsuexec).
An example: When you have a file called ‘item’ (like Nucleus uses for FancyURL’s) and want it to be parsed by the server as php you use the following code in your .htaccess file:
However, because our servers use phpsuexec this will result in an internal server error. To solve this you can simply use SetHandler instead of ForceType, so your .htaccess-file becomes:
SetHandler application/x-httpd-php php_value
On a server without phpsuexec it is possible to use the php_value statement in a .htaccess file to change the settings of php (actually overwrite the settings from php.ini). On a sever with phpsuexec this will also result in a server error. To solve this you can use a php.ini file which you put in the same folder as where you would have put your .htaccess file. In that php.ini file you can change all the php values. You only have to put the values you want to modify in that file. By example if you want to set the short_open_tag to Off you would have used short_open_tag? = off in your .htaccess file. Using a php.ini file this results in:
[ PHP ]
short_open_tag = Off
- Force Type
How To fix 500 Internal Server Error
Fixing this error is quite easy to accomplish, just follow the steps below and you are good to go.
#1 Open the Error Logs tool, located in the Logs section of the cPanel.
#2 Reload the web page that is causing the error.
#3Reload the Error Logs page.
#4Search the error logs for your IP Address for any errors associated with it, your IP address is located at the top of the page.
With the above done, you may find out that the problem may basically be
* File or Folder Permissions
* Bad code or syntaxes in your .htaccess
* Improperly configured php.ini