2013年7月22日月曜日

Ubuntu 12.04 LTSにmod_wsgi 3.4をインストール

Apache(/usr/local/apache2にインストール)からPythonを使えるように、 Quick Installation Guideを参考にしてインストール。


まず、任意のフォルダにソースコードをダウンロードして展開。
$ wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
$ tar xvzf mod_wsgi-3.4.tar.gz

続いて、configureを実行するとapxsコマンドが見つからないとエラーになる。
$ cd mod_wsgi-3.4
$ ./configure
checking for apxs2... no
checking for apxs... no
checking Apache version... ./configure: line 1704: apxs: command not found
...

apxsコマンド(Apacheのbinフォルダ)のパスを指定して、再度、configureを実行。
正常終了したら、そのままmakeを実行。すると、今度はPython.hが見つからないとエラーに。
$ ./configure --with-apxs=/usr/local/apache2/bin/apxs
$ make
...
mod_wsgi.c:142:20: fatal error: Python.h: No such file or directory
compilation terminated.
...

Python.hをインストールして、再びビルド。
成功したら、そのまま make installを実行。
$ sudo apt-get install python-dev
$ make
$ sudo make install
...
Libraries have been installed in:
   /usr/local/apache2/modules
...

最後に、Apacheのhttpd.confにwsgi_moduleを追加してインストール作業は終了。
$ sudo vi /usr/local/apache2/conf/httpd.conf
...
LoadModule wsgi_module modules/mod_wsgi.so
...

あとは、Quick Configuration Guideを参考に、簡単なWSGI Applicationを作成して動作確認。しかし、1点だけ注意が必要。このサイトのhttpd.confの例はApache 2.4未対応です。アクセスしてもForbiddenとなります。以下のように修正する必要があります。
<Directory /usr/local/www/wsgi-scripts>
Require all granted
# Order allow,deny
# Allow from all
</Directory>

0 件のコメント:

コメントを投稿