Mac apache 配置python CGI

2018-11-14  本文已影响8人  S大偉

Mac OS X默认是安装了 Apache 的,要启动 Apache 服务需要手动通过命令行开启。

启动Apache 两种方法

第一步

启动Apache

sudo apachectl start
sudo apachectl -v
#可以查看到Apache的版本信息

停止Apache

sudo apachectl stop

启动后,直接浏览器访问http://127.0.0.1http://localhost ,就可以看到下图,说明打开成功。

It works.png

这里已经完成了一半,😂

第二步

sudo vim /etc/apache2/httpd.conf
sudo apachectl restart

第三步

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print "Content-type:text/html"
print                               # 空行,告诉服务器结束头部
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello Word - 我的第一个 CGI 程序!</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>'
print '</body>'
print '</html>'
cd /Library/WebServer/CGI-Executables
chmod 755 test.py
屏幕快照 2018-11-14 下午3.17.05.png
 localhost/cgi-bin/test.py
testpy.png

到这里就告一段落啦。

web站点的根目录为

/Library/WebServer/Documents/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Word - 我的第一个 CGI 程序!</title>
</head>
<body>
<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>
</body>
</html>
http://localhost/test.html
test_html.png

好了,到此就告一段落啦。

注意:查看编辑配置文件,可以查看很多的相关配置,如端口号:80等

sudo vim /etc/apache2/httpd.conf
上一篇 下一篇

猜你喜欢

热点阅读