1、安装apache
2、brew install httpd24
3、vim /usr/local/etc/httpd/httpd.conf
将注释去掉,如下:
<IfModule mpm_prefork_module>
LoadModule cgi_module libexec/mod_cgi.so
</IfModule>
<IfModule !mpm_prefork_module>
LoadModule cgid_module libexec/mod_cgid.so
</IfModule>
4、在/usr/local/var/www/cgi-bin 放入CGI1.py
5、chmod 777 /usr/local/var/www/cgi-bin/CGI1.py
6、apachectl restart
7、http://localhost:9090/cgi-bin/CGI1.py
!/usr/bin/python
-- coding: UTF-8 --
print("Content-type:text/html")
print('')
print('<html>')
print('<head>')
print('<title>Hello</title>')
print('</head>')
print('<body>')
print('<h2>hello CGI 啦啦啦啦啦</h2>')
print('</body>')
print('</html>')
//头一行要加上这两句注释,不然会报语法错误