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.
- 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
- 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
- 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.
- 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.