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:
- Including the AddHandler with .py files to the .conf file
- Adding ExecCGI to the "Options Indexes" line in the .conf.
- Making sure the first thing output is ""Content-Type:text/html" with 2 end of line characters.
- 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.
- 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>")
Apache+mod_wsgi
+Gunicorn+Flask
(or maybeApache+mod_wsgi+Flask
) – furas