CentOS 5.6 に Python 2.7.1 と mod_wsgi 3.3 をインストール
VMWare Fusion 3 で簡単にサーバの設定をいぢることができるようになったので、早速前から気になってた mod_wsgi を試してついでに Python も 2.7.1 にしてみたのでメモ。
Django も 1.3 にしてみたけど、それはまた次回。
Python 2.7.1 のインストール
前に Python 2.6.6 を CentOS 5.5 にインストールしたけど、同じ手順でインストールできた。
まずはライブラリを入れておく
[paraches@localhost myTest]$ sudo yum install zlib zlib-devel
Python 2.7.1 をダウンロードして展開
[paraches@localhost myTest]$ wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz [paraches@localhost myTest]$ tar zxvf Python-2.7.1.tgz [paraches@localhost myTest]$ cd Python-2.7.1
オプション付けて configure する。
[paraches@localhost myTest]$ ./configure --with-threads --enable-shared
Modules/Setup を修正(コメントを一カ所外す)
[paraches@localhost Python-2.7.1]$ cat Modules/Setup | grep zlib # Andrew Kuchling's zlib module. # This require zlib 1.1.3 (or later). # See http://www.gzip.org/zlib/ zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz [paraches@localhost Python-2.7.1]$
後は make して make install
[paraches@localhost Python-2.7.1]$ make [paraches@localhost Python-2.7.1]$ sudo make install
ライブラリの設定して(/etc/ld.so.conf.d/python2.7.conf を作って登録)
[paraches@localhost Python-2.7.1]$ cat /etc/ld.so.conf.d/python2.7.conf /usr/local/lib [paraches@localhost Python-2.7.1]$ sudo /sbin/ldconfig
動作確認
[paraches@localhost Python-2.7.1]$ /usr/local/bin/python Python 2.7.1 (r271:86832, Apr 18 2011, 22:42:06) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Alias 作ってみたりとかも前回と同じで。
mod_wsgi 3.3 をインストール
まずはココからダウンロードして展開
[paraches@localhost myTest]$ http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz [paraches@localhost myTest]$ tar zxvf mod_wsgi-3.3.tar.gz [paraches@localhost myTest]$ cd mod_wsgi-3.3
configure して
[paraches@localhost mod_wsgi-3.3]$ ./configure checking for apxs2... no checking for apxs... /usr/sbin/apxs checking Apache version... 2.2.3 checking for python... /usr/local/bin/python configure: creating ./config.status config.status: creating Makefile [paraches@localhost mod_wsgi-3.3]$
後は make して make install
この時、Python を --enable-shared 付けてビルドしておかないと -fPIC 云々のエラーになる。
[paraches@localhost mod_wsgi-3.3]$ make [paraches@localhost mod_wsgi-3.3]$ sudo make install
動作確認
/etc/httpd/conf.d/ に mod_wsgi 用の設定ファイル mod_wsgi.conf を置く。
[paraches@localhost conf.d]$ cat mod_wsgi.conf LoadModule wsgi_module modules/mod_wsgi.so WSGIScriptAlias / /var/www/cgi-bin/hello.py [paraches@localhost conf.d]$
この例では / にアクセスしたら /var/www/cgi-bin/hello.py が呼び出されるので、/var/www/cgi-bin/hello.py を用意する。
[paraches@localhost cgi-bin]$ cat hello.py def application(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/plain')] start_response(status, response_headers) return ["Hello world!"] [paraches@localhost cgi-bin]$
apache に設定を読み込ませる。
[paraches@localhost conf.d]$ sudo /etc/init.d/httpd reload httpd を再読み込み中: [ OK ] [paraches@localhost conf.d]$
以上で Python 2.7.1 と mod_wsgi 3.3 はインストール完了。
次回は Django 1.3 を mod_wsgi を使って動かしてみる。