python::wsgiを入れ・・・たい (mod_wsgi)
前提として、
・apacheは2.2.17でyumインストールしてある。
・pythonは2.5.1をソースrpmでインストールしてある。
yumでは入らないらしい。
mod_wsgiをソースをもってきてコンパイルする。
yum install python-devel yum install httpd-devel wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz tar xzf mod_wsgi-3.3.tar.gz cd mod_wsgi-3.3 ./configure make make install (略) ---------------------------------------------------------------------- Libraries have been installed in: /usr/lib/httpd/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/lib/httpd/modules/mod_wsgi.so
あとは、httpd.conf関連に記述する。
手元の環境では、Includeファイルに書いた。
## ## file: /etc/httpd/conf.d/wsgi.conf ## # DSOモジュールの指定。面倒くさがりなのでフルパス。 LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so # WSGIアプリケーションは、アプリケーション毎にエイリアスを指定しないといけないっぽい。 # --> ファイルアップロードしただけで参照できる方法があるかもしれないけれど・・・。 # --> とりあえず、エントリポイントURLと実体ファイルを関連付ける WSGIScriptAlias /wsgi /var/www/html/test.py
apacheの再起動が必要。
sudo /etc/rc.d/init.d/httpd restart
test.py を書く。
def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
http://localhost/wsgi にアクセス
Hello World!
出来たー。