3.1 Installing mod_python

To install mod_python, we simply run:

yum install mod_python

3.2 Configuring Apache

Now we must configure Apache so that it can handle Python files. There are two ways of doing so. The first (and default) one is to use the Publisher Handler. It allows you to write pure Python scripts with the extension .py that will be interpreted by Apache. The second way is the PSP Handler. PSP stands for Python Server Pages. It allows you to embed Python code directly in HTML code, similar to PHP. PSP files have the extension .psp.

3.2.1 The Publisher Handler

To enable the Publisher Handler, we must edit the mod_python configuration which you can find in /etc/httpd/conf.d/python.conf. This file contains many examples - we make a backup of it and create that file again from scratch. I'm using the default Fedora/CentOS document root /var/www/html here in the<Directory> directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.publisher:

 
 

cp /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf_orig
cat /dev/null > /etc/httpd/conf.d/python.conf
vi /etc/httpd/conf.d/python.conf

LoadModule python_module modules/mod_python.so

<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>

Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please leave out the <Directory ...>...</Directory> part in the above file since that would enable mod_python globally for the directory in question. In ISPConfig you can enable mod_python on a per-website basis instead which gives you more control whether a website can use mod_python or not.

Restart Apache afterwards:

/etc/init.d/httpd restart

Now we create a little Python test script (e.g. /var/www/html/test.py) with pure Python code in it...

vi /var/www/html/test.py

def index(req):
return "Test successful";

... and call it in a browser (e.g. http://192.168.0.100/test.py). If all goes well, it should display Test successful in your browser.

3.2.2 The PSP Handler

To enable the PSP Handler, we must edit the mod_python configuration which you can find in /etc/httpd/conf.d/python.conf. This file contains many examples - we make a backup of it and create that file again from scratch. I'm using the default Fedora/CentOS document root /var/www/html here in the <Directory>directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.psp:

cp /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf_orig
cat /dev/null > /etc/httpd/conf.d/python.conf
vi /etc/httpd/conf.d/python.conf

LoadModule python_module modules/mod_python.so

<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .psp
PythonHandler mod_python.psp
PythonDebug On
</Directory>

Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please leave out the <Directory ...>...</Directory> part in the above file since that would enable mod_python globally for the directory in question. In ISPConfig you can enable mod_python on a per-website basis instead which gives you more control whether a website can use mod_python or not. Also note that ISPConfig does not support the PSP Handler - it uses the Publisher Handler.

Restart Apache afterwards:

/etc/init.d/httpd restart

Now we create a little PSP test script (e.g. /var/www/html/test.psp) with HTML and Python code in it...

vi /var/www/html/test.psp

<html>
<body>
<h1><% req.write("Hello!") %></h1>
</body>
</html>

... and call it in a browser (e.g. http://192.168.0.100/test.psp). If all goes well, it should display Hello! in your browser.

fedora安装mod_python的更多相关文章

  1. Ubuntu 安装mod_python配置Apache2

    在Ubuntu上搭建Python运行环境,mod_python是不可少的(据说mod_swgi也是可以的,没有亲测).使用命令安装mod_python. 安装: apt-get install lib ...

  2. Linux(Fedora) 安装 Oracle XE Database

    Fedora 安装 Oracle XE Database Fedora 20Oracle XeOracle VM VirtualBoxFedora 安装oracle 数据库 环境: Oracle VM ...

  3. Fedora安装Snapd和Snap软件包

    导读 Snappy包管理器是一个跨发行版的包管理器.它最初是为Ubuntu系统构建的,但现在其他主要的Linux发行版( Fedora, Linux Mint, RHEL, OpenSUSE,Arch ...

  4. fedora安装字体

    #fedora安装新字体 将自己现有的字体复制到/usr/share/fonts/自己起个名字/ 例如我要安装下载的苹果苹方字体 #cp 我这个文件夹的地址/* /usr/share/fonts/Pi ...

  5. fedora安装后的配置

    fedora安装后的一些配置 (mirror)源 换源 默认从fedora官网下载太慢,考虑换用国内的源(镜像站点),推荐中科大.阿里云.浙大.网易等的源. 比如我用浙大ZJU的源http://mir ...

  6. fedora 安装新字体 courier new xxx

    fedora安装新字体 1.将windows字体拷贝到/usr/share/fonts/truetype下面,文件夹名字可以随便起 cp /media/c/WINDOWS/Fonts/* /usr/s ...

  7. fedora安装后,yum命令不能使用,Cannot retrieve metalink for repository: fedora. Please verify its path and try again 解决方法

    fedora安装后,yum命令不能使用,Cannot retrieve metalink for repository: fedora. Please verify its path and try ...

  8. 2.0 Linux系统的安装之Fedora安装单系统(2)

    2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...

  9. fedora安装ep,forge,fusion等第三方软件库

    fedora安装ep,forge,fusion等第三方软件库 官方的发行版 抛弃了有 版权争议的 软件, 特别是 包括很多第三方的 多媒体软件, 如播放 mp3, flv等的软件 解码器 这就要靠 使 ...

随机推荐

  1. 跟我一起实战美团网一之[nodemon] app crashed - waiting for file changes before starting...

    环境准备 第一步安装 npm install -g npx npx create-nuxt-app at-app 与事件相关的包我们再安装一次 npm install --update-binary ...

  2. 乐观、悲观锁、redis分布式锁

    悲观锁总是假设最坏的情况,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会阻塞直到它拿到锁(共享资源每次只给一个线程使用,其它线程阻塞,用完后再把资源转让给 ...

  3. [转]iMPACT Spartan-6 FPGA - "WARNING:iMPACT:2217-Error shows in the status register, CRC Error bit is Not 0"

    AR# 45304 iMPACT Spartan-6 FPGA - "WARNING:iMPACT:2217-Error shows in the status register, CRC ...

  4. 洛谷 P2886 [USACO07NOV]牛继电器Cow Relays

    题面 解题思路 ## floyd+矩阵快速幂,跟GhostCai爷打赌用不用离散化,最后完败..GhostCai真是tql ! 有个巧妙的方法就是将节点重新编号,因为与节点无关. 代码 #includ ...

  5. ArcSDE 10.0与ArcSDE10.1的又一个区别

    ArcSDE10.0 安装后直接在创建sde表空间和sde用户的时候创建了sde服务:而sde10.1可以直接先通过ArcMap10.1直连数据库,创建sde表空间.sde用户.然后在有必要的情况下再 ...

  6. PAT甲级——A1025 PAT Ranking

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  7. 作业test

    views Car <template> <div class="car"> <Nav/> <div class="wrap&q ...

  8. 855. Exam Room

    维护一个数据结构要满足:一个教室线性排列的座位 0 ... N-1 调用seat 入座一个距离最近学生最远的座位 调用leave x 离座一个位置为x的学生 由于N最多是 10e9 所以选择维护 学生 ...

  9. CString转const char

    CString转换成const char      需要考虑一个因素: 你使用是否为unicode 不使用unicode: CString  Cstr("aaaaaaa"); co ...

  10. mysql 安装失败 start service执行不下去

    简单说一下自己安装mysql的经历坑点,新手应该都会遇到.新买了一个电脑,第一次安装的情况:在网上下载好几个不同的mysql,安装都在最后一步执行的时候,执行不下去,最后打开客户端,就是闪一下就消失了 ...