2008年2月23日土曜日

【Python】 mod_pythonをソースからコンパイルしてインストール

ApacheのPythonモジュール、mod_pythonをソースコードからコンパイルしてからインストールする手順。

以下のサイトからmod_python-3.x.x.tgzをダウンロードする。
http://httpd.apache.org/modules/python-download.cgi?Preferred=http%3A%2F%2Fftp.kddilabs.jp%2Finfosystems%2Fapache

必要なパッケージをインストールする。
sudo apt-get install python-dev


ダウンロードしたmod_python-3.x.x.tgzを解凍する。
tar zxvf mod_python-3.x.x.tgz


展開したディレクトリに移動してコンパイル、インストール開始。
./configure --with-apxs=/usr/local/apache2/bin/apxs
make
sudo make install


/usr/local/apache2/conf/httpd.confをroot権限で編集する。
以下を追加する。
LoadModule python_module modules/mod_python.so
<Directory "/path/to/DocumentRoot">
  AddHandler mod_python .py
  PythonHandler hello
  PythonDebug On
</Directory>


必要に応じて、DocumentRoot、ServerName、DirectoryIndex等を変更する。

Apache再起動。
/usr/local/apache2/bin/apachectrl restart


hello.pyを以下の内容でDocumentRoot直下に作成。
from mod_python import apache
def handler(req):
  req.content_type = "text/html"
  req.send_http_header()
  req.write("Hello World")
  return apache.OK


ブラウザで確認する。
http://localhost/hello.py

ラベル: , , ,

0 件のコメント:

コメントを投稿

登録 コメントの投稿 [Atom]

この投稿へのリンク:

リンクを作成

<< ホーム