Django 1.7はPython 2.7以上でないと使えないんですが、CentOS 6.5のデフォルトはPython 2.6だったので別に2.7をインストールしました。
その後Apacheで使用するにはmod_wsgiを2.7を使うようにコンパイルしなおさなくてはいけなくてちょっと面倒でした。。
Python 2.7インストール
必要なパッケージをインストールして
1 2 3 4 5 6 7 8 | # yum groupinstall "development tools" # yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel # wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz # tar xzf Python-2.7.8.tgz # cd Python-2.7.8 # ./configure --prefix=/usr/local --enable-unicode=ucs4 --with-threads --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" # make |
なんか一部モジュールに必要なものが足りないとか言われる
1 2 3 4 5 6 | Python build finished, but the necessary bits to build these modules were not found: _bsddb bsddb185 dbm dl gdbm imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. |
1 2 | yum install gdbm-devel |
他はよくわからないのでスルーしてaltinstall
1 2 | make altinstall |
altinstallするとデフォルトの2.6を置き換えないようにインストールされます。
1 2 3 4 5 | # python2.7 -V Python 2.7.8 # python -V Python 2.6.6 |
pipインストール
1 2 3 4 | # wget https://bootstrap.pypa.io/get-pip.py # python2.7 get-pip.py # pip2.7 install 色々 |
pipと入力したときにPATHの優先順位の問題で/usr/local/binにあるpip2.7のほうが優先になってしまいましたがとりあえず放置。
mod_wsgiインストール
念のため既存のmod_wsgiを削除
1 2 | yum remove mod_wsgi |
1 2 3 4 5 | # wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.2.8.tar.gz -O mod_wsgi-4.2.8.tar.gz # tar xzf mod_wsgi-4.2.8.tar.gz # cd mod_wsgi-4.2.8 # ./configure --with-python=/usr/local/bin/python2.7 |
(ちなみに最初4.3.0を落としたらインストールが上手くいかなかったので4.2.8にしました。)
makeしたらapxsが無いと言われたので
1 2 | # yum install httpd-devel |
1 2 3 | # make # make install |
Apacheの設定ディレクトリにmod_wsgi読み込みを加えます。
1 2 3 | # vim /etc/httpd/conf.d/wsgi.conf LoadModule wsgi_module modules/mod_wsgi.so |
これでApacheを再起動したらエラー
1 2 3 4 | # /etc/init.d/httpd restart httpd を停止中: [OK] httpd を起動中: httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/wsgi.conf: Cannot load /etc/httpd/modules/mod_wsgi.so into server: libpython2.7.so.1.0: cannot open shared object file: No such file or directory |
共有ライブラリが見つからないと言われたのでld.so.confに/usr/local/libを加えます。
1 2 3 4 | # vim /etc/ld.so.conf /usr/local/lib # ldconfig |
これでApache起動成功し、使用バージョンも2.7.8になってました。