Skip to content

Instantly share code, notes, and snippets.

@makotoworld
Created December 6, 2011 06:32
Show Gist options
  • Save makotoworld/1437054 to your computer and use it in GitHub Desktop.
Save makotoworld/1437054 to your computer and use it in GitHub Desktop.
apache2.2 + python2.7 + mod_wsgi3.3 + Django1.3.1環境構築メモ
pip install django
cd /home/xxxx/htdocs/
dajango-admin.py startproject mysite
cd mysite
mkdir templates
vim setting.py
db の設定
テンプレートの場所の設定
wget http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.2.21.tar.gz
tar zxvf httpd-2.2.21.tar.gz
cd httpd-2.2.21
./configure
make && make install
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
tar zxvf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3
./configure --with-apxs=/usr/local/apache2/bin/apxs
--with-python=/usr/local/bin/python
make && make install
インストールできたら、 mod_wsgi が使えるように httpd.conf の編集。
httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
apachectl graceful
myapp.wsgi
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]
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
django.wsgi
import os, sys
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
httpd.conf
先頭にある#コメントを削除
Include conf/extra/httpd-vhosts.conf
</pre>
httpd-vshost.conf
<pre lang="zsh">
Alias /robots.txt /usr/local/wsgi/static/robots.txt
Alias /favicon.ico /usr/local/wsgi/static/favicon.ico
AliasMatch /([^/]*.css) /usr/local/wsgi/static/styles/$1
Alias /media/ /usr/local/wsgi/static/media/
<Directory /usr/local/wsgi/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi
<Directory /usr/local/wsgi/scripts>
Order allow,deny
Allow from all
</Directory>
/usr/local/apache2/bin/apachectl graceful
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
tar zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py install
which python
python -V
ctrl+Z で対話シェルモードから脱出。
入っているならyum remove python-devel で削除する。
yum remove python-devel
途中で削除するリストが出てきて、OKなら "y" を押してリターン。
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar zxvf Python-2.7.2.tgz
cd Python-2.7.2
./configure --enable-shared CFLAGS="-fPIC" CXXFLAGS="-fPIC" LDFLAGS="/usr/local/lib"
make && make install
cp libpython2.7.so* /usr/lib64/
ldd /usr/local/bin/python
lib64 を見ているかどうかと、not found になっていないか確認。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment