動機
テンプレートエンジン動かしたら次はやっぱりWebサーバから叩かないといけないでしょう。
試行錯誤
とりあえずMacPortsでmod_python25を入れる
$ sudo port install mod_python25 (略) ---> Activating mod_python25 3.3.1_1 Error: Target org.macports.activate returned: Not a directory Error: Status 1 encountered during processing.
なんかエラーでてるけどとりあえずactivateはされてるみたいなんで保留。
このテストに従って設定を行う。mptest.pyというファイルを/path/to/directoryに作成
$ emacs /opt/local/apache2/conf/httpd.conf <Directory "/path/to/directory"> AddHandler mod_python .py PythonHandler mptest PythonDebug On </Directory>
from mod_python import apache def handler(req): req.write("Hello World!") return apache.OK
で、Apache2.2を再起動。
$ sudo /opt/local/apache2/bin/apachectl start
mptest.pyにアクセスしてみたらInternal Server Errorが出た。とりあえずログを見てみる。
$ less /opt/local/apache2/logs/error_log [Sat Dec 13 11:26:46 2008] [error] python_init: Python version mismatch, expected '2.5.2', found '2.3.5'.
ありゃ、Apache2が元からTigerに入ってる古いPython見に行ってる。設定を変更。
<Directory "opt/local/apache2/htdocs/python"> AddHandler mod_python .py PythonHandler mptest PythonDebug On PythonPath ['/opt/local/bin/python2.5'] </Directory>
しかし同様のエラー。あっれ、なにがおかしいんだ?どれ、じゃあ/usr/libの設定を変更してみるか。
$ ln -s /opt/local/libpython2.5.dylib /usr/lib/libpython2.5.dylib $ ln -s /opt/local/libpython2.5.dyilb /usr/lib/libpython2.dylib $ ln -s /usr/lib/libpython2.dylib /usr/lib/libpython.dylib $ ln -s /opt/local/python2.5 /usr/lib/python2.5
で、もう一度MacPortsでmod_python25をインストールしてみたけど、やっぱり同様。だったら今度はソースからインストールだ。
$ wget http://ftp.riken.jp/net/apache/httpd/modpython/mod_python-3.3.1.tgz $ tar xzf mod_python-3.3.1.tgz $ ./configure --with-apxs=/opt/local/apache2/bin/apxs --with-python=/opt/local/bin/python2.5 $ sudo make connobject.c: In function '_conn_read':. connobject.c:142: error: request for member 'next' in something not a structure or union. apxs:Error: Command failed with rc=65536
はあ?調べてみてエラーを対処する。
これでもう一度./configureしてみると今度はこんな感じでまたエラー。
/opt/local/share/apr-1/build/libtool --silent --mode=link /usr/bin/gcc-4.0 -o mod_python.la -rpath /opt/local/apache2/modules -module -avoid-version finfoobject.lo hlistobject.lo hlist.lo filterobject.lo connobject.lo serverobject.lo util.lo tableobject.lo requestobject.lo _apachemodule.lo mod_python.lo -L/opt/local/lib -Wl,-F/opt/local/Library/Frameworks -Wl,-framework,Python -u _PyMac_Error /Versions// -L/opt/local/lib -lm -framework Python -ldl /usr/bin/ld: can't locate framework for: -framework Python
もうらちがあかないからこの方法でインストールするの一旦中止。
方法
しかたないので、上記の方法は全部却下してめちゃめちゃになったMacPortsを全部入れ直し。まずMacPortsのアンインストール。
$ sudo rm -rf \ /opt/local \ /Applications/MacPorts \ /Library/Tcl/macports 1.0 \ /Library/LaunchDaemons/org.macports.* \ /Library/Receipts/MacPorts*.pkg
で、MacPortsを再度インストールして個々のパッケージをインストール。このときpython25, apache2, mod_python25の順番は守る。
python25をインストールするときにデフォルトをPython2.5にするようなアナウンスがでるのできちんと設定をする。(これがいけなかったのか。。。)
$ sudo port install python25 (略) $ sudo port install python-select $ sudo python-select python2.5
apache2, mod_python2.5のインストールが終わったあとは上記と同様に設定をすれば動きます。一日がこれで終わってしまった。