Windows configures Apache to run the Python script CGI mode in the browser _linux

Source: Internet
Author: User
Tags python script run python script

Now that you've installed 2.6 of Python and support 2.6 of ERIC4, you don't want to reinstall 2.5来 to continue configuring Apache Mod_python.

Later, I found an article running Python as CGI in Apache in Windows, which tells you to run Python script in the CGI mode instead of Mod_python. And this python for Windows.

The procedure is:

Open httpd.conf, find "#ScriptInterpreterSource Registry", remove the previous comment # (add yourself if you can't find this line)
Find the "Options Indexes followsymlinks" and add "execcgi" to the back. (the "Indexes" best also can be removed, because if not removed, the directory does not index.html this file, it will display all the files under the directory list, so there is a security vulnerability problem. If indexes is removed and there is no index.html file, a Forbidden page will be displayed.
Find "AddHandler cgi-script. CGI" and Add. py at the back. If not, you can add your own "AddHandler cgi-script. Py"
Restart Apache (sometimes restart can cause Apache to die, so people in this situation can stop and start again)
And then create a test.py script,

Print "content-type:text/html"
Print ""
Print "print "Hello World"
Print "</body>

Running Http://localhost/test.py,Hello World Two words in a browser indicates that it is working correctly.

In addition, some error prompts are as follows:

No Scriptinterpretersource Registry is added, and a Internal Server error error occurs.
Without adding execcgi, you will receive 403 Forbidden you don ' t have permission to access/test.py on the this server.
Without adding AddHandler cgi-script. py, the content will be displayed in the text text format in the browser.
Note:

The intention of adding Scriptinterpretersource registry is to have Windows use Registry to find the place where Python is installed.
EXECCGI is to allow Python script to run under any directory, because Apache defaults to let CGI scripts run in the Cgi-bin directory. And I put test.py under Htdocs Run will appear 403 forbidden problem. So you need to add execcgi so that you can run it under Htdocs. py script. But excecgi will have a problem with security vulnerabilities. It would be safer to use fastcgi. But the premise is to need to install fastcgi.
CGI mode is slower than Mod_python mode. So there's a chance to try Mod_python mode on other computers later.

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.