mod-pythonをubuntuで動かす

ubuntuにてsynapticでapache2とmod-pythonを入れてからの流れ。

# ①を追加
sudo vi /etc/apache2/sites-available/default

# ディレクトリ作成
sudo mkdir /var/www/py

# ②を追加
sudo cat > /var/www/py/helloworld.py

# 再起動
sudo /etc/init.d/apache2 restart
# ①
<Directory /var/www/py>
    AddHandler mod_python .py
    PythonHandler helloworld
    PythonDebug On
</Directory>
# ②
from mod_python import apache
 
def handler(req):
        req.log_error('handler')
        req.content_type = 'text/html'
        req.send_http_header()
        req.write('<html><head><title>Hello World</title></head><body>')
        req.write('Hello World!')
        req.write('</body></html>')
        return apache.OK

http://localhost/py/helloworld.py
動いた。