(1) 安裝
# aptitude install libapache2-mod-python
(2)創建測試文件
默認的apach root 目錄是/var/www
在/var/www下面創建文件夾python_test,并在此目錄下面創建文件mptest.py
內容如下:
from mod_python import apache
def handler(req):
??? req.log_error('handler')
??? req.content_type = 'text/html'
??? req.send_http_header()
??? req.write('Hello World')
??? return apache.OK
(3)配置
修改/etc/apache2/sites-enable/000-default
??? <Directory /var/www/python_test>
??? ??? AddHandler mod_python .py
??? ??? PythonHandler mptest
??? ??? PythonDebug on
??? </Directory>
重新啟動apache2
#/etc/init.d/apache2 restart
(4)測試
瀏覽器輸入 http://localhost/python_test/mptest.py
如果能看到
Hello World
就說明配置成功。
如果有錯誤或者異常就說明配置沒有成功。
|----------------------------------------------------------------------------------------|
版權聲明 版權所有 @zhyiwww
引用請注明來源 http://www.aygfsteel.com/zhyiwww
|----------------------------------------------------------------------------------------|