apache 同時(shí)支持php,python cgi配置方法
1. 我用的是mac系統(tǒng)默認(rèn)安裝了apache祖娘,這里就為給大家介紹apache的安裝過(guò)程
2. 首先配置虛擬域名:
#vim?/etc/apache2/httpd.conf
找到下面這行
#Include /private/etc/apache2/extra/httpd-vhosts.conf
將前面的#號(hào)去掉
再打開(kāi)/etc/apache2/extra/httpd-vhosts.conf 將內(nèi)容改成以下的樣子
DocumentRoot?"/Users/user/Project/php"
ServerName?test.php.com
ErrorLog?"/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog?"/private/var/log/apache2/dummy-host.example.com-access_log"?common
Options?Indexes?FollowSymLinks?MultiViews
AllowOverride?None
Order?deny,allow
Allow?from?all
將文件添加可讀權(quán)限
chomd -R 755 /Users/user/Project/php
添加hosts
sudo vi /etc/hosts 以管理員身份打開(kāi)hosts文件抵皱,追加一行
127.0.0.1???????test.php.com
保存重啟APACHE
#sudo apachectl restart
3. 配置apache 支持python cgi 加入CGI支持
#vim /etc/apache2/httpd.conf
LoadModule?cgi_module?/usr/lib/apache2/modules/mod_cgi.so?//默認(rèn)有則不需要加
AddHandler?cgi-script?.cgi?.pl?.py?.sh?
//?我們加入這一句莉擒,使CGI支持?perl和python?和shell腳本钝计,這行一般都存在去掉前面的注釋即可
#sudo vim /etc/apache2/extra/httpd-vhosts.conf 將以下行加入文件底部
DocumentRoot?"/Users/user/Project/python/cgi-bin"
ServerName?cgi.python.com
ScriptAlias?/cgi-bin/?"/Users/user/Project/python/cgi-bin"
ErrorLog?"/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog?"/private/var/log/apache2/dummy-host.example.com-access_log"?common
Options?+ExecCGI?-MultiViews?+SymLinksIfOwnerMatch
AllowOverride?None
Order?deny,allow
Allow?from?all
添加hosts
sudo vi /etc/hosts 以管理員身份打開(kāi)hosts文件恋博,追加一行
127.0.0.1? ? ? cgi.python.com
#cd /Users/user/Project/python/
#chmod -R 755 cgi-bin/
重啟apache
#sudo apachectl restart
4. 測(cè)試php、cgi私恬、py
#vim test.py
#!/usr/bin/python
print?'Content-Type:?text/html\n\nhello?world'
保存
#vim test.cgi
#!/usr/bin/python
print?'Content-Type:?text/html\n\nhello?world'
保存
能打印hello world 一切正常
本文轉(zhuǎn)自CSDN Blog: