1.安装apache2 sudo apt-get install apache2html
2.配置apache2 vim /etc/apache2/sites-enabled/ 000-default.confpython
找到 ScriptAlias /cgi-bin/ ....chrome
将后面的目录改为你想要的cgi文件的目录 如 /var/www/html/cgi-bin/apache
进入 /etc/apache2/mods-enabled 目录,看是否存在cgid.load,若是没有建立它,在文件中输入vim
LoadModule cgid_module /usr/lib/apache2/modules/mod_cgid.so 服务器
AddHandler cgi-script.cgi .pyrest
最后重启apache2服务器 sudo /etc/init.d/apache2 restarthtm
写一个例子ip
#!/usr/bin/env python2
print "Content-type:text/plain"
print
print 'Hello,world!'get
保存到/var/www/html/cgi-bin/test.cgi
设置运行权限 chmod 755 test.cgi
sudo
最后经过chrome访问 http://localhost/cgi-bin/test.cgi
能够看到界面显示 Hello,world!