dedtech.info

Information about computer technology.

Allow Apache To Execute Python Scripts

This blog post will explain how to allow Apache to execute python scripts. Find the http.conf file and add Indexes, FollowSymLinks, and ExecCGI to the Options configuration string.

Options Indexes FollowSymLinks ExecCGI

Find the AddHandler configuration string and change it to the string below.

AddHandler cgi-script .cgi .py

These lines have to be added to a server side .py file named test.py.

#!C:\python\python.exe
print("Content-Type: text/html\n")

Add this statement to test.py to have it display something on the web browser.

print("<html><body><h1>python works</h1></body></html>")

This is what the whole code looks like.

#!C:\python\python.exe
print("Content-Type: text/html\n")
print("<html><body><h1>python works</h1></body></html>")

Test the code in the web browser by navigating to this URL below.

http://localhost/test.py

Leave a Reply

Your email address will not be published. Required fields are marked *