sudo apt-get install apache2
sudo apt-get install libapache2-mod-python
设置:
允许Mod_Python
cd /etc/apache2/mods-enabled/
sudo ln -s ../mods-available/mod_python.load mod_python.load
修改apache2配置文件
cd /etc/apache2/sites-available/
sudo gedit default
On line 10 you should have:
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
Change it to:
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
重启apache2服务
sudo /etc/init.d/apache2 restart
测试:
sudo gedit /var/www/test.py
内容:
def index(req):
return "Test successful";