2
votes

I'm in internet programming, and we are doing .cgi, but for the life of me, I cannot get my .cgi script to run at all, I know other people have it working, but mine just refuses to run. Any suggestions?

#!/usr/bin/env python

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

I have chmod 755 the file multiple times, i have tried using #!/usr/bin/python and #!usr/local/bin/python. I tried putting it in a folder named cgi-bin and I've made sure that it is saved with unix line endings, but all I ever get is internal server error. I know I had it working in class, but now it just refuses to run, any help guys? Thanks?

2
The only way you're going to find out for sure is to look in the server logs. They're in different places on different operating systems, so I can't tell you where to look. Find the logs and you will find an error message explaining exactly why a 500 is being returned. - Jim Garrison
well i'm on Ubuntu, and the server is running apache on CentOS, does that help? - convergedtarkus
on the centos server check the apache logs. They should be at: /var/log/httpd/error_log - monkut

2 Answers

1
votes

Wild guess: you are using Python 3, so your print statements have to be print function calls:

print("Content-type: text/html")
etc...
1
votes

Ok, this is a really easy fix that I totally missed. First off Ned Batchelder correctly pointed out that my code is python 2 (which is weird since I use python 3) but the problem is the print statement after the, print("Content-type: text/html"). The second print statement has to be print("") not just print(). So i feel a little stupid, but that fixed the issue for me, hope this helps someone else!