Run python in the CGI of the Apache server under Mac OS

Source: Internet
Author: User

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:

/library/webserver/cgi-executables

Files placed in this directory can be accessed via the following URL:

Http://localhost/cgi-bin/file-name

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:

Cd/library/webserver/cgi-executables

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:

http://localhost/cgi-bin/test.py

Run python in the CGI of the Apache server under Mac OS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.