==[[Django 運用環境の構築]]==
[[Django]] | [[Python]] |
=====注意点=====
#Pythonのバージョンにより [[Python]]のバージョンにより mod_python をソースからコンパイルする
#httpd_devel をインストールしないと、mod_python がコンパイルできない
#PostgreSQLの共有ライブラリを [[PostgreSQL]]の共有ライブラリを /usr/lib 等にコピーして利用できるようにしておく必要あり
===インストール===
====mod_python のインストール====
=====Apache、Python Apache、[[Python]] は以下のバージョン(うまくいかなければ改めてソースから・・・)=====
*mod_python 3.2.8-3.1
*httpd-2.2.3-5
*python 2.6.2 r262
<blockquote>Pythonを [[Python]]を 2.4 から 2.6にしていたため、yumで取得したバイナリとは Pythonのバージョンが異なり失敗。以下、ソースからコンパイルを行う。2[[Python]]のバージョンが異なり失敗。以下、ソースからコンパイルを行う。2.4 なら問題ない。</blockquote>
# yum install mod_python
Setting up Install Process
Setting up repositories
Reading [[R]]eading repository metadata in from local files
Parsing package install arguments
Resolving Resol[[vi]]ng Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mod_python to pack into transaction set.
mod_python-3.2.8-3.1.i386 100% |=========================| 26 kB 00:00
---> Package mod_python.i386 0:3.2.8-3.1 set to be updated
--> Running [[R]]unning transaction check
Dependencies Resolved[[R]]esolved
=============================================================================
Package Arch Version Repository [[R]]epository Size
=============================================================================
Installing:
Install 1 Package(s)
Update 0 Package(s)
Remove [[R]]emove 0 Package(s)
Total download size: 257 k
Downloading Packages:
(1/1): mod_python-3.2.8-3 100% |=========================| 257 kB 00:00
Running [[R]]unning Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running [[R]]unning Transaction
Installing: mod_python ######################### [1/1]
Complete!
====[[Windows ]] 用に以下のサイトでバイナリが配布されている====
*http://ftp.riken.jp/net/apache/httpd/modpython/win/3.3.1/
<blockquote>Python2[[Python]]2.6 用は提供されていない模様 2010/01/21時点</blockquote>
===ソースからインストール===
*http://httpd.apache.org/modules/python-download.cgi
====コンパイル====
=====configure=====
*apxs および Pythonのバージョンも正しく検知されたっぽい[[Python]]のバージョンも正しく検知されたっぽい
# ./configure --with-apxs=/usr/sbin/apxs
:
checking for --with-python... no
checking for python... /usr/local/bin/python
checking [[Python ]] version... 2.6 checking [[Python ]] install prefix... /usr/local
checking checking where python libraries are installed... /usr/local/lib/python2.6
config.status: creating dist/Makefile
<Directory "/var/www/html/pytest">
AddHandler mod_python .py
PythonHandler [[Python]]Handler mptest PythonDebug [[Python]]Debug On
</Directory>
=====[[Apache ]] を再起動し、mptest.pyにアクセス=====
*再起動
# /sbin/service ser[[vi]]ce httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]
*http://192.168.24.14/pytest/mptest.py
[[File:0347_mod_py01.jpg]]
===[[Django ]] の設定===
====httpd.confの編集====
*http://michilu.com/django/doc-ja/modpython/
<Location "/py/mysite">
SetHandler python-program
PythonHandler [[Python]]Handler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonPath "sys.path+['/var/www/html/py']"
PythonDebug [[Python]]Debug On
</Location>
=====以下のエラー=====
<blockquote>yum でバイナリをインストールしたため、以下のエラー。ソースコードから再インストールを行う。</blockquote>
*現在の環境は、もともとPython2.4 がデフォルトで入っていたところに、[[Django インストール] [|2.6を入れいている]]が、mod_python 自体もバイナリは Python2.4 でコンパイルされている? Mod_python error: "PythonHandler [[Python]]Handler django.core.handlers.modpython"
Traceback (most recent call last):
# yum erase mod_python
:
Running [[R]]unning Transaction
Removing : mod_python ######################### [1/1]
Removed[[R]]emoved: mod_python.i386 0:3.2.8-3.1
Complete!
====[[Django 最初のアプリケーション 1|チュートリアルで作成したアプリケーション] [チュートリアルで作成したアプリケーション]を呼び出してみる。====
*http://192.168.24.14/py/mysite/polls/
=====エラー=====
ImproperlyConfigured: Error loading psycopg2 module: libpq.so.5: cannot open shared object file: No such file or directory
*[[PostgreSQL 8.3.5 インストール|バックエンドに設定]]した、[PostgreSQLのライブラリを認識していないようだ|http://wiki.minaco.net/index.php?cmd=read&page=Python%2FDjango%2F%E3%83%81%E3%83%A5%E3%83%BC%E3%83%88%E3%83%AA%E3%82%A2%E3%83%AB [バックエンドに設定|PostgreSQL 8.3.5 インストール]]した、[PostgreSQLのライブラリを認識していないようだ]
# cp /usr/local/pgsql/lib/libpq.so.5 /usr/lib
=====mysite.urls.py=====
urlpatterns = patterns('',
(r'^py/mysite/firsttest/$', 'mysite.firsttest.views[[vi]]ews.index'),
)
=====mysite.firsttest.views[[vi]]ews.py=====
# -*- encoding: utf-8 -*-
from django.http import HttpResponseHttp[[R]]esponse
def index(request):
return HttpResponse('Hello [[Django]]!')
=====OK=====
[[File:0348_mod_py02.jpg]]