Configure Apache in Windows to run the CGI Mode of Python script in a browser

Source: Internet
Author: User

Now, because Python 2.6 is installed and eric4 2.6 is supported, you do not want to reinstall 2.5 to configure mod_python under Apache.

Later I found an articleArticleRunning python as CGI in Apache in Windows describes how to use the CGI Mode instead of mod_python to run Python scripts. This article also describes python for Windows.

The practice is:

Open httpd. conf, find "# scriptinterpretersource Registry", and remove the comment # (if this line cannot be found, add it to it by yourself)
Find the "Options indexes followsymlinks" sentence and add "execcgi" to it. (That "indexes" is the best way to get rid of it. If no index.html file exists in the directory, all files in the directory list will be displayed. Therefore, there is a security vulnerability. If indexesis removed and no index.html file exists, a forbidden page is displayed)
Find "addhandler CGI-script. cgi" and add. py to the end. If you do not have this sentence, you can add "addhandler CGI-script. py" by yourself"
Restart Apache (sometimes restart will cause Apache to die, so in this case, you can stop and start again)
Then create a test. py script,

Print "Content-Type: text/html"
Print ""
Print "<HTML> Print "Hello World"
Print "</body>

Run the http: // localhost/test. py and hello World characters in the browser.

In addition, some error messages are as follows:

If the scriptinterpretersource registry is not added, Error 500 internal server error occurs.
If execcgi is not added, the 403 forbidden you don't have permission to access/test. py on this server will appear.
If addhandler CGI-script. py is not added, the content is displayed in the browser in text format.
Note:

The intention of adding scriptinterpretersource registry is to allow windows to use registry to find the python installation place.
Execcgi allows Python scripts to run in any directory, because Apache runs CGI scripts in the cgi-bin directory by default. When I put test. py under htdocs to run it, the 403 Forbidden problem will occur. Therefore, execcgi must be added to run. py script in htdocs. However, excecgi may have security vulnerabilities. FastCGI is safer. The premise is that FastCGI can be installed.
The CGI Mode is slower than the mod_python mode. So I will have the opportunity to try the mod_python mode on other computers in the future.

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.