---
title: "ubuntu下配置apache的mod_python"
author: "vivimusing"
date: "2009-06-09T15:47:45Z"
tags: []
slug: "ubuntu-apache-mod-python"
draft: false
lastmod: "2009-06-09T15:51:32Z"
id: 405232
url: "https://vivimusing.iteye.com/blog/405232"
---

在读mod\_python的安装文档时候遇到点问题，现在解决了，和大家分享下。

 

我的系统是ubuntu的9.04版本，用apt-get安装apache和mod\_python的

[](http://man.chinaunix.net/develop/python/mod_python/mod_python.html#head-f43fb742b32fd6930e7c30926f22c88fcfe019e5)

[这里是我参考的mod\_python的中文文档](http://man.chinaunix.net/develop/python/mod_python/mod_python.html#head-f43fb742b32fd6930e7c30926f22c88fcfe019e5)

 

在2.3.2 配置 Apache小节中，因为apt-get安装的，在/etc/apache2/mods-available/python.load文件，里面内容是

 

```
LoadModule python_module /usr/lib/apache2/modules/mod_python.so
```

 

我们在/etc/apache2/mods-available/目录下面新建一个python.conf来配置和python相关的应用的信息

&lt;Directory /var/wwwt&gt;  
        AddHandler mod\_python .py  
        PythonHandler mptest  
        PythonDebug On  
        AddType text/html;qs=1.0 .py  
        AddType text/html;qs=0.9 .html  
        AddType text/html;qs=0.8 .txt  
 &lt;/Directory&gt;

最后的3行比较重要，像我这里用firefox浏览的时候，不能解析文档，而变成直接下载文件了。

这里我参考2篇文章解决的 [1](http://www.nabble.com/-CPyUG:79160--%E5%85%B3%E4%BA%8Emod_python%EF%BC%8C%E6%B5%8F%E8%A7%88.py%E6%8F%90%E7%A4%BA%E4%B8%8B%E8%BD%BD%E7%9A%84%E4%B8%80%E4%B8%AA%E6%84%8F%E5%A4%96%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95-td22075181.html) [2](http://www.modpython.org/pipermail/mod_python/2006-June/021475.html)

 AddType text/html;qs=1.0 .py  
 AddType text/html;qs=0.9 .html  
 AddType text/html;qs=0.8 .txt

然后用ln命令将这2个文件建立一个连接到 /etc/apache2/mods-enabled/中

重启下apache命令是/etc/init.d/apache2 restart

在/var/www/下面建立一个文件mytest.py

内容是

from mod\_python import apache

def handler(req):  
    req.write("Hello World!")  
    return apache.OK

在浏览器中测试下，如果你看到Hello World! 就成功了。