zoukankan      html  css  js  c++  java
  • fedora安装mod_python

      

    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.

  • 相关阅读:
    美国首位女计算机博士荣获今年图灵奖
    此人需要关注一下
    Microsoft的壮大与IBM对Sun的收购
    文章介绍:Sexy Lexing with Python
    程序员的门道
    闲谈:敏捷与否的区分方法、对组织内部人员的现实作用与长远利益
    聊聊最俗的工厂相关话题
    人之患在好为人师
    TIOBE的头头儿和“反Java”的教授
    敏捷的核心究竟是什么
  • 原文地址:https://www.cnblogs.com/felixjia/p/3694870.html
Copyright © 2011-2022 走看看