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