Configure Apache to support Python in CGI mode under Windows

Source: Internet
Author: User
Tags print print

Apache Configuration


Find DocumentRoot in httpd.conf:

Allow directories to execute CGI:

DocumentRoot "D:\WWW" <directory/> Options Indexes followsymlinks multiviews execcgi allowoverride all Ord Er allow,deny Require all granted</directory>

Only allow CGI programs to be executed in the special directory:

scriptalias/cgi-bin/"d:/program/phpstudy/apache/cgi-bin/"

Let Apache identify the py file as a CGI program:

AddHandler cgi-script. cgi. py

The above is configured to complete Apache.

However, there are times when we may encounter:

     > > [ Sat APR 13:30:03 2006] [ERROR] [client 127.0.0.1] C:/Program
     > > Files/apache group/a pache2/cgi-bin/test.py is not executable; Ensure
     > > interpreted scripts has "#!" first line
     > & Gt [Sat APR 01 13:30:03 2006] [ERROR] [Client 127.0.0.1] (9) Bad file
     > > Descriptor:don ' t know what to spawn child Process:c:/program Files/ap Ache
     > > group/apache2/cgi-bin/test.py
    

At this point you can try adding: ' Scriptinterpretersource Registry ' at the end of the configuration file

Let's start with an example program:

test.py

#! D:\Program\Python27\python.exe print "content-type:text/html" Print print "<H1>HELLO,WORLD!&L T;/h1> "

Write a CGI program to be aware that

First: #! There should be no space in front, followed by the interpreter;

Second, the directory of the interpreter program such as Python is correct;

Thirdly, as the requirements of HTTP protocol, we must output HTTP headers;

Four, in the presence of HTTP headers, it is important to print a blank line behind the headers, or the server will error;

Five, the wrong program in the Python idle execution, verify correctness;

Finally, in case of uncertainty, look at the Error.log file under Apache's Logs folder to determine the problem.


Run http://127.0.0.1/cgi-bin/test.py

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4B/8D/wKiom1Quy5SSlXgHAAAj9TfcTKs924.jpg "title=" Qq20141004001409.png "alt=" Wkiom1quy5sslxghaaaj9tfctks924.jpg "/>

Configure Apache to support Python in CGI mode under Windows

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.