久しぶりに動かしたPythonのDjangoアプリが動かなくなっていた。
もしもメンテナンスするときが来たら困るので、復旧しておく。
当時のバージョンで再構築
CentOS6、Apache2.2、Python2.7、MySQL5.7
標準のPythonが2.6なので、SCLを使いpython2.7を使う。
yum install centos-release-SCL
yum install scl-utils*
yum --disablerepo=ius install python27 python27-scldevel python27-MySQL-python
※iusをリポジトリを使っているため、CentOS-SCLo-scl-rh版を使うように強制
sclでPython2.7の環境に切り替えて作業を行う。
djangoのバージョンは当時のバージョンに合わせる。
scl enable python27 bash
pip install --upgrade pip
pip install django==1.7.0
pip install mod-wsgi
![](https://stat.ameba.jp/user_images/20200308/12/oaksjp/bd/05/p/o0642036414724795652.png?caw=800)
httpdのconfに追記
/etc/httpd/conf.d/python27-mod_wsgi.conf
<IfModule !python_module>
<IfModule !wsgi_module>
LoadModule wsgi_module /opt/rh/python27/root/usr/lib64/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
</IfModule>
</IfModule>
バーチャルホスト設定
<VirtualHost *:80>
DocumentRoot /path/to/xxx_webapp/htdocs
ServerName your_domain.com
~(略)~
<Directory "/path/to/xxx_webapp/htdocs">
~(略)~
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIScriptAlias /path /path/to/xxx_webapp/xxx/wsgi.py
WSGIProcessGroup your_domain.com
WSGIDaemonProcess your_domain.com python-path=/path/to/xxx_webapp:/opt/rh/python27/root/usr/lib64/python2.7/site-packages
</VirtualHost>