トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

BugTrack-その他のメモ/21

R備忘録 /状態空間モデリング/donlp2/その他のメモ

mod_python + CentOS 5.4

  • 投稿者: みゅ
  • カテゴリ: Python
  • 優先度: 普通
  • 状態: 完了
  • 日時: 2010年02月09日 17時45分57秒

内容

  • mod_pythonを動作させるまで
  • めっちゃ簡単

手順

  • CentOS 5.4をインストールする.
  • 普通にサーバーとか、開発ツールをCentOSインストール時に選択していれば、apache2(httpd)もmod_pythonもインストールされている.
  • /etc/sysconfig/httpd.confだったか、「-D PYTHON」を追加する
  • /var/www/htmlにPython用のフォルダを作成する.名前はなんでもいいのがだが、ここでは「test2」とする.ださくてすいません.
  • /etc/httpd/conf.d/python.confに以下を追加する.
<Directory "/var/www/html/test2">
        AddHandler mod_python .py
        PythonHandler mod_python.publisher
        PythonDebug On
</Directory>
  • これでOK.
  • /var/www/html/test2フォルダにPythonのスクリプトを作成する.ここでは動作確認用に「myscript.py」というのを作る.
from mod_python import apache
import sys

def handler(req):
    req.content_type = "text/plain"
    req.write("Hello World!")

    return apache.OK

def test(req):
	req.content_type = "text/plain"
	req.write("This is test object!\n")
	a = sys.path
	for m in a:
		req.write(m+'\n')
	return apache.OK
  • apacheを再起動する.
/etc/init.d/httpd restart

コメント