Friday, August 21, 2009

Howto Fix Internal Server Error

Recently I encounter one problem: When running a Perl CGI (or Python) script on Fedora 10 machine, I saw the "Internal Server Error" message in my browser. The message said something like "please check the server's error-log for more information." and contact web server administrator.

I checked the Apache error log, since I am running Fedora, the error log file is located at /var/log/httpd/error_log. The error messages says:


[client 127.0.0.1] (2) No such file or directory: exec of '/var/www/cgi-bin/cgiscriptname.cgi' failed, referer: http://localhost/your.html

[client 127.0.0.1] Premature end of script headers: cgiscriptname.cgi, referer: http://localhost/your.html


I googled the solutions from Internet, but most of them are saying the permissions are not correct. But I changed the permissions for all the files and directories, but still doesn't work, and got the same error messages.

Finally I found the solution by checking the web server's configuration - httpd.conf which located at /etc/htttpd/conf/. By default in Fedora, the cgi-bin section is configured as following:


<Directory "/var/www/cgi-bin">
AllowOverride None<
Options None
Order allow,deny
Allow from all
</Directory>


So I noticed Options None was the one cause the problem. After I change it to the following:

Options ExecCGI


And restart the apache web service, the "Internal Server Error" message is gone. The scripts are running fine now.

By the way, I think the following tips might be useful in your cases.

  1. The perl path or the python path in your script should be match your server environment settings.

    For perl, the header of your script should look like:

    #!/usr/bin/perl


    For Python, the header of your script should look like:

    #!/usr/bin/python


  2. The second thing that you need to check is the permission of your CGI scripts.

    • Your home directory should have permissions of 701

    • Your .www (and any sub-directories containing you scripts) should have permissions of 701

    • Your CGI/Python scripts should have permissions of 701

    • Files that your CGI/Python script needs to read (for example an image file) should have permission of 604


  3. The next thing is checking the owner and gorup of your CGI/Python script. Usually the CGI/Python script and the enclosing directory must have the same owner/group of your web server. You should go to /etc/httpd/conf/httpd.conf to check the web server owner. In Fedora, both should be apache by default.

  4. The last thing that you might need to check is your scripts, some of them may transfered from Windows via FTP service. It should be transfered under ASCII mode. So you need to convert it to Unix line feeds by typing the following command:

    # tr -d '\r' <yourscript.py> yourscriptconv.py


    And run the new script which you converted.


Hope this will help you to solve your Internal Server Error Problem.

No comments :

Post a Comment

Comments System

Disqus Shortname