I'm a porter. Running Python Programs on the Mac OS X Apache Web Server
The MAC OS X operating system includes a pre-configured Apache Web server and also includes the libraries needed to run Py Thon. Thus, Python CGI scripts can be run without any configuration changes to the Apache configuration as long as the scripts a Re placed in the correct location and given the correct file permissions.
This guide assumes you is using OS X Leopard, although the steps should be the same or similar for earlier versions of OS X.
The default location to place CGI programs for the OS X Apache installation are in the following directory:
Files placed in this directory can be accessed via the following URL:
In order for Apache to is able to execute the CGI script, the permissions on the file must is set correctly. For example, open EditRocket and create a file called test.py with the following contents. Save this file to The/library/webserver/cgi-executables directory.
#!/usr/bin/pythonprint "content-type:text/html" Printprint "
Open a terminal window (applications, Utilities, terminal). Execute the following command:
Then execute the following (if prompted, enter your password)
sudo chmod 755 test.py
Your now has a Python program, test.py, saved with the correct permissions in The/library/webserver/cgi-executables Direc Tory.
Now, we need to restart the Web server to make sure the changes take effect. To restart, do the following:
1. Go to System Preferences-sharing View
2. Uncheck the Web sharing box. Then check the Web sharing box again. This would start and stop the Apache Web server.
You can test this page by entering the following in your Web browser:
Run python in the CGI of the Apache server under Mac OS