0

I am trying to run a very simple "Hello World" program with Apache. However, Apache returns a 500 Internal Server Error when it tries to execute my python file. I've read several similar topics on here and tried the suggestions, no luck. Things I have tried:

  1. Including the AddHandler with .py files to the .conf file
  2. Adding ExecCGI to the "Options Indexes" line in the .conf.
  3. Making sure the first thing output is ""Content-Type:text/html" with 2 end of line characters.
  4. Adding a shebang line to the top of the python file to direct to the Python interpreter. I'm not sure if I'm doing this part right.
  5. Restarting Apache

The tools I am using include:

  • Windows 7
  • Python 3.5
  • Apache 2.4

My code: The HTML File (in the htdocs folder in the Apache folder):

<form action="/cgi-bin/hello_get.py" method="post">
First Name: <input type="text" name="first_name">  <br />

Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>

The python file (in the cgi-bin folder):

# Note that I tried this without the C:/ also
#!C:/Users/MyName/workspace/Flask/flask/Scripts

# Import modules for CGI handling
import cgi, cgitb

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
first_name = form.getvalue('first_name')
last_name  = form.getvalue('last_name')

print("Content-Type:text/html\r\n\r\n")
print("<html>")
print("<head>")
print("<title>Hello - Second CGI Program</title>")
print("</head>")
print("<body>")
print("<h2>Hello %s %s</h2>" % (first_name, last_name))
print("</body>")
print("</html>")
2
  • I know Flask but I am required to use Apache :/ Commented Jan 27, 2016 at 22:25
  • then use Apache+mod_wsgi + Gunicorn+Flask (or maybe Apache+mod_wsgi+Flask) Commented Jan 27, 2016 at 22:27

1 Answer 1

2

I figured it out.

In my shebang line, instead of:

#!C:/Users/MyName/workspace/Flask/flask/Scripts

I should have:

#!C:/Users/MyName/workspace/Flask/flask/Scripts/python.exe

I thought my shebang should have a path to where the python interpreter lives, I didn't realize I needed the actual full path of the interpreter.

It is working now.

So to recap, if you are having this issue after following these instructions: http://editrocket.com/articles/python_apache_windows.html Make sure that if you are using Windows the path is the full absolute path from the C:/ drive to the python.exe executable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.