Mac下apache支持cgi运行python3程序

20 篇文章 0 订阅
8 篇文章 0 订阅

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/bin
sudo apachectl start

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

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值