Debian安装和配置mod_python

原文地址 :http://www.cyberciti.biz/faq/ubuntu-mod_python-apache-tutorial/

1.Install mod_python

Open terminal and type the following command:
$ sudo apt-get update
$ sudo apt-get install libapache2-mod-python libapache2-mod-python-doc

2.Configure mod_python

You need to create directory to host your python scripts. Type the following command:
$ sudo mkdir /var/www/py
Give your account permission to access the scripts:
$ sudo chown yourname:www-data /var/www/py
Now, open /etc/apache2/sites-available/default, enter:
$ sudo -s
# vi /etc/apache2/sites-available/default

Add the following config code:

 
   <Directory /var/www/py>
        AddHandler mod_python .py
        PythonHandler hello
        PythonDebug On
    </Directory>
 

Save and close the file. Restart Apache2 server:
# /etc/init.d/apache2 restart
# tail -f /var/log/apache2/error.log

You should see mod_python/3.3.1 Python/2.5.2 loaded:

[Tue Mar 17 02:42:18 2009] [notice] FastCGI: process manager initialized (pid 15572)
[Tue Mar 17 02:42:18 2009] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Tue Mar 17 02:42:18 2009] [notice] mod_python: using mutex_directory /tmp
[Tue Mar 17 02:42:18 2009] [notice] Apache/2.2.9 (Ubuntu) mod_fastcgi/2.4.6 PHP/5.2.6-2ubuntu4.1 with Suhosin-Patch mod_python/3.3.1 Python/2.5.2 mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming normal operations

3.How do I test mod_python?

Simply create the script as follows:
$ vi /var/www/py/hello.py
The following simple mod_python program serves as a good test:        

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>Testing mod_python</title></head><body>')
        req.write('Hello World!')
        req.write('</body></html>')
        return apache.OK

 Save and close the file. Now fire a webbrowser and type the url:
http://localhost/py/hello.py
You hould see "Hello World!" on screen.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值