2009年2月7日 星期六

debian下apache2安裝mod_python模組

首先安裝好apache2
sudo aptitude install apache2
安裝好後預設的web context根目錄會在/var/www下

安裝mod_python模組
sudo aptitude install libapache2-mod-python

設定網站支援mod_python
vim /etc/apache2/sites-available/default
在Directory /var/www的項目中
把內容改為:
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
存檔

重新啟動apache
/etc/init.d/apache2 restart

這樣就完成mod_python的安裝與設定了
現在可以建立python程式

vi /var/www/test.py
內容為:
#!/usr/bin/env python
def index(req):
return "Test successful";

以browser連到 http://localhost/test.py
就可以看到 Test successful 的輸出結果。

沒有留言: