Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

internal server error (500) in simple cgi script

Tags:

python

apache

cgi

I am trying to run a simple cgi script after configuring my server.

My script looks like this:

print "Content-type: text/html"
print
print "<html><head><title>CGI</title></head>"
print "<body>"
print "hello cgi"
print "</body>"
print "</html>"

When I go to my scripts url http://127.0.0.1/~flybywire/cgi-bin/main.py I get:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

And in error.log I get the following:

[error] (8)Exec format error: exec of '/home/flybywire/www/cgi-bin/main.py' failed [error] [client 127.0.0.1] Premature end of script headers: main.py

Other info: Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.4.6 Server at 127.0.0.1 Port 80

like image 332
flybywire Avatar asked Sep 23 '09 08:09

flybywire


People also ask

Why does my browser keep saying 500 internal server error?

Basically, the server that hosts the website you are trying to reach cannot complete your request. The issue causing the 500 error message could be a permissions or security issue with the server, the website reaching its memory limit, bad files on the site or a bad cache on your device, among other issues.

Is 500 internal server error permanent?

The “500 Internal Server Error” can affect your entire website or only parts of it. It can be permanent, appear sporadically, or result in a blank page. These errors may also come from updates carried out automatically by components of your website and therefore occur without any action taken on your side.

How do I force a 500 error?

As for the error page, if you just want to view the page, you can navigate to it directly... if you want to force a 500 error to happen, just change the db password in your . env to something that doesn't work. That specific problem/error was due to an incorrect path set in php. ini.


2 Answers

Also, save the file (if this is a Linux server) with Unix line endings. You did make it executable using chmod +x didn't you?

You can use #!/usr/bin/env python to cover the current running Python version if you're running in various environments (hence the env part).

like image 87
Dave Everitt Avatar answered Oct 23 '22 18:10

Dave Everitt


You might need a #!/usr/bin/python at the top of your script to tell Apache to use Python to execute it. At least, I did that and it worked for me :-) .

like image 28
Paul Stephenson Avatar answered Oct 23 '22 20:10

Paul Stephenson