程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Apache CGI programming, how to configure Apache and conf files in win10

編輯:Python

I've been studying recently python Of CGI Programming , So I almost fell apache. After looking for a circle of online information, I found , Now a lot of python CGI Programming information , I found it all in liux Configuration operations in ,windows There are few operations in .

If according to liux The operation , De configuration conf file , Newcomer Xiaobai will basically have some problems . By groping , I finally found windows In the system conf Correct configuration method of files , It's simple , It is different from most configurations on the Internet .

Let's get to the point :

First step ,apache After downloading , Can be apache The installation files of are placed in the root directory , the apache24 The folder is placed in the top-level directory of the drive .

 

The second step , Just like many operations on the Internet : stay cmd Navigate to in the console apache24 Location of installation files , Input httpd -k install After the command is executed, you can install .

During installation , You may encounter various problems , Here I encountered a very common problem :apache Can't bind 80 port . To address this issue , The most direct reason , Namely 80 The port is occupied by another program , So you just need to IIS service ( It may also be another program , Direct application management , Or use “netstat -ano”) Can be closed

The third step , modify conf file .

Win10 In the system ,apache From the conf The file only needs to be modified in two places :

The first place , take <Directory ‘your cgi-bin path’><Directory> This place Options Change to ExecCGI that will do . After modification, it is shown in the red box in the figure

 

The second place , take ‘#AddHandler cgi-script .cgi .pl’ The first sentence is revised to read ‘AddHandler cgi-script .cgi .pl .py’ that will do . The modified appearance is shown in the red box below .

 

Here is a small detail by the way :

 

label 1 The contents of the notes on the show ExecCGI The role of , If you want to use CGI Programming words , You need to add an option ‘Options ExecCGI’. therefore , I added the label here 2 The content of .

After my test : stay ‘<Directory ‘your cgi-bin path’><Directory>’、‘AddHandler cgi-script .cgi .pl .py’ These two places add ‘Options ExecCGI’ It's all right , Choose one or both , Can run correctly CGI Programming files .

Many unknown parameters , These notes roughly say , You want to know more about , You can have a patient look .

Step four , stay cgi-bin Add python file . I added here python file , It is the file finally displayed in the browser . As shown in the figure below .

Step five , Compiling python file , Be sure to add python The specific address of the running environment program , Like a sign 1 Shown , This is my python Specific installation location . As the label in the figure 1 Shown .

secondly ,‘charset="text/html;utf-8"’ In a sentence , Don't forget ’text/html;’ This tag , Otherwise, there will be Chinese garbled . As the label in the figure 2 Shown

Step six , Restart apache service . open win+r Open the runner , Input ‘service.msc’ Start the service ,

And then click apache24, Restart the service , So that conf The modified content is refreshed . As shown in the figure :

 

Step seven , Enter... In the browser :http://localhost/cgi-bin/test.py, You can see python To be displayed in the file html Content , As shown in the figure .

I'm the son of Science , One is learning python New programmers , Aspire to engage in testing 、 Game development 、 big data 、AI Direction ! Pay attention to me , Share with you from time to time python Programming dry goods ! Make a little progress every day , Grow a big step every day !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved