Configure Apache web server for Python on Windows

1. Install Python and Apache

Python: .


2. Configure Apache to run Python CGI

The next step is to edit ‘httpd.conf’ apache configuration file located in the apache install directory in the conf directory. Search the httpd.conf file for the line

Options Indexes FollowSymLinks

Add ExecCGI to the end of the line. The line should now look similar to the following (NOTE: there may be more options listed):

Options Indexes FollowSymLinks ExecCGI

Next, search for the following:

#AddHandler cgi-script .cgi

Uncomment this line by removing the # in front of the line, and add a .py to the end of the line. The new line should look like this:

AddHandler cgi-script .cgi .py

3. Restart Apache

Now, the apache web server needs to be restarted. You can do this either via the Apache service located in the services control panel or via the Start -> All

Programs -> Apache . . . -> Control Apache Server

menu option.

4. Run a test Python page

You can use the EditRocket hello world Python sample web page template for a test Python page. This is located in File -> New From Template ->

python -> Sample_Web_Page. The following is an example of the template:


print “Content-type: text/html”


print “<html><head>”

print “”

print “</head><body>”

print “Hello.”

print “</body></html>”

Note the line #!/usr/bin/python. This line needs

changed to match the location of your Python

installation. For example,


Here is an example assuming Python is installed in the C:\Python34 location


print (“Content-type: text/html”)

print (“”)

print (“<html><head>”)

print (“”)

print (“</head><body>”)

print (“Hello.”)

print (“</body></html>”)

Save this file as to your htdocs folder under your apache installation directory. Open your web browser and type in your apache host (and :port if the port is something other than 80) followed by, for example



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s