ubuntu14 下配置cgi

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!

相關文章
相關標籤/搜索