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
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.
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.
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.
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).
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 :-) .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With