LoginSignup
2
0

More than 5 years have passed since last update.

CentOS 6 + Python3.5.2 + Django 1.10 本番デプロイ

Last updated at Posted at 2016-11-09

CentOS 6.8 で Django1.10の本番デプロイ環境構築

はじめに

今回、さくらのVPSを借りる機会があり、PythonとDjangoの開発環境・本番デプロイ環境が作りを行なったので、備忘録代わりに記事にしました。ほとんど、解説なしですが、参考にしてもらえればと思います。

目指す環境

- Cent OS 6.8
- python 3.5.2
- django 1.10
- Apache 2.2.15
- mod_wsgi 4.5.2

確認

1. OSの確認 : cat /etc/centos-release
2. Pythonの確認 : python -V
3. Django の確認 : django-admin.py --version
条件が1個でも違う方は試してみる価値ありです。

  iptablesでブロックされていない前提、ホントはきっちりしとこう。

yum update , yum upgrade : もはやお作法

開発用のツール群をインストール

1. yum -y install wget gcc zlib-devel gdbm-devel readline-devel httpd-devel httpd
2. yum -y install sqlite-devel openssl-devel tk-devel bzip2-devel

Python3.5.2のインストール

1. mkdir tmp
2. cd tmp
3. wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
4. tar -xzf Python-3.5.2.tgz
5. cd Python-3.5.2
Pythonをコンパイル&インストール
6. ./configure --enable-shared
7. make && make altinstall
実際に利用できるよう、パスの設定を行う
8. echo "/usr/local/lib/python3.5" > /etc/ld.so.conf.d/python33.conf
9. echo "/usr/local/lib" >> /etc/ld.so.conf.d/python33.conf
10. ldconfig

mod_wsgiのインストール

1. cd ../ <= tmpへ戻れれば、なんでもいいです。
mod_wsgiダウンロード
2. wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.2.tar.gz
3. tar -xzf 4.5.2.tar.gz
4. cd mod_wsgi-4.5.2/
mod_wsgi インストール
5. ./configure --with-python=/usr/local/bin/python3.5
6. make && make install

Djangoのインストール

pip3.5のアップグレード、djangoのインストール
1. /usr/local/bin/pip3.5 install --upgrade pip
2. /usr/local/bin/pip3.5 install django

mod_wsgi、Djangoのプロジェクト設定(実は一番めんどい)

http://rady-time.com/post-222/ (参考文献3)
上記参照。ディレクトリの設定などを同じにするとなお分かりやすいです。

その後

Djangoのプロジェクトが置いてあるディレクトリを再帰的にパーミッション変更
1. chmod 777 -R /path/to/Django'sProject
SELinuxというセキュリティの機構を解除
2. sudo setenforce 0

その他

1. Django上のALLOWED_HOSTS設定に気をつけよう
2. 分からなかったらApacheのエラーログを見ること(参考文献4)

参考文献

1. http://hermesian.hatenablog.com/entry/2016/05/03/223729
2. http://nobuta05.hatenablog.com/entry/2015/09/28/172606
3. http://rady-time.com/post-222/
4. http://d.hatena.ne.jp/midori_kasugano/20091203/1259832929
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0