Mac下apache支持cgi运行python3程序

来源:互联网 发布:maxwell软件百科 编辑:程序博客网 时间:2024/06/14 15:55

Mac预装的apache让我不知所措,各种奇葩问题。
1,homebrew安装apache

brew tap homebrew/apache  //更新下仓库

2.执行安装

brew install httpd24

3.修改httpd配置

vi /usr/local/etc/apache2/2.4/httpd.conf

大约在52行修改端口号为:
Listen 90
158行至163行,将模块包的注释去掉,修改为如下:

<IfModule mpm_prefork_module>    LoadModule cgi_module libexec/mod_cgi.so</IfModule><IfModule !mpm_prefork_module>    LoadModule cgid_module libexec/mod_cgid.so</IfModule>

第356行提到cgi运行文件存放目录:ScriptAlias /cgi-bin/ “/usr/local/var/apache2/cgi-bin/”
将我们试运行的文件get.py放到这个目录下面,get.py内容如下:

#!/usr/bin/python# -*- coding: UTF-8 -*-print "Content-type:text/html"print                               print '<html>'print '<head>'print '<meta charset="utf-8">'print '<title>Hello Word !</title>'print '</head>'print '<body>'print '<h2>Hello Word! </h2>'print '</body>'print '</html>'

授权执行文件

chmod 777 /usr/local/var/apache2/cgi-bin/get.py

4.启动安装的httpd

cd /usr/local/Cellar/httpd24/2.4.25/binsudo apachectl start

5.查看运行结果:
浏览器输入:http://127.0.0.1:90/cgi-bin/get.py

这里写图片描述

原创粉丝点击