CentOS 7.4 に
手順を
python Mac OS High Sierra に
前提
前提となる
OS の
Version cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
Python の
Version python3.6 -V Python 3.6.4
DB の
Version
Postgres をインストール済みです。 psql (9.6.6)
Apache の
Version httpd -v Server version: Apache/2.4.29 (CentOS) Server built: Oct 23 2017 14:34:32
インストール
wagtailを
インストール python3.6 -m pip install wagtail ------------------------------------------ Successfully installed Unidecode-1.0.22 Willow-1.0 django-modelcluster-3.1 django-taggit-0.22.2 django-treebeard-4.2.0 djangorestframework-3.6.4 html5lib-0.999999999 wagtail-1.13.1 ------------------------------------------
おそらく まっさらな 状態からだと、 多くの ライブラリが インストールされるかと 思います。
参考に、pip list
の結果を 貼り付けて おきます。 1 python3.6 -m pip list --format=columns ------------------------------------------ Package Version -------------------------- ----------- beautifulsoup4 4.6.0 bleach 2.1.2 certifi 2017.11.5 chardet 3.0.4 coreapi 2.3.3 coreschema 0.0.4 cssmin 0.2.0 Django 1.10.8 django-appconf 1.0.2 django-braces 1.12.0 django-compressor 2.2 django-contrib-comments 1.8.0 django-critical 0.1.1 django-crontab 0.7.1 django-csp 3.3 django-csp-reports 1.1 django-extensions 1.9.8 django-filter 1.1.0 django-htmlmin 0.10.0 django-modelcluster 3.1 django-oauth-toolkit 0.12.0 django-request 1.5.4 django-rest-swagger 2.1.2 django-robots 3.0 django-taggit 0.22.2 django-treebeard 4.2.0 djangorestframework 3.6.4 filebrowser-safe 0.4.7 future 0.16.0 grappelli-safe 0.4.7 html5lib 0.999999999 idna 2.6 itypes 1.1.0 Jinja2 2.10 Markdown 2.6.11 MarkupSafe 1.0 mecab-python3 0.7 Mezzanine 4.2.3 mezzanine-api 0.6.1 mezzanine-pagedown 1.0 mezzanine-pubsubhubbub-pub 0.0.5 mock 2.0.0 mod-wsgi 4.5.24 numpy 1.14.0 oauthlib 2.0.1 openapi-codec 1.3.2 pbr 3.1.1 Pillow 5.0.0 pip 9.0.1 psycopg2 2.7.3.2 Pygments 2.2.0 pymdown-extensions 4.7 pymongo 3.6.0 python-dateutil 2.6.1 python-memcached 1.59 pytz 2017.3 rcssmin 1.0.6 requests 2.18.4 requests-oauthlib 0.8.0 rjsmin 1.0.12 scikit-learn 0.19.1 scipy 1.0.0 setuptools 36.6.0 simplejson 3.13.2 six 1.11.0 sklearn 0.0 typing 3.6.2 tzlocal 1.5.1 Unidecode 1.0.22 uritemplate 3.0.0 urllib3 1.22 wagtail 1.13.1 webencodings 0.5.1 Willow 1.0 ------------------------------------------
プロジェクト作成
ディレクトリ移動して、wagtail
コマンドで、プロジェクトを 作成します。 root ユーザーでcd /var/www/xxx wagtail start project
作成したので、 オーナを 変えて おきます。 chown -R apache:apache project
設定ファイルの 修正
言語設定
base.py
の、LANGUAGE_CODE
と、TIME_ZONE
を
- /var/www/xxx/project/project/base.py
LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo'
管理画面の URLを 変更する
デフォルトだと、
- /var/www/xxx/project/project/urls.py
urlpatterns = [ #url(r'^django-admin/', include(admin.site.urls)), url(r'^admin/django-admin/', include(admin.site.urls)), #url(r'^admin/', include(wagtailadmin_urls)), url(r'^admin/admin/', include(wagtailadmin_urls)),
wsgi.py の 設定変更
wagtail は、
wsgi.py は、
- /var/www/xxx/project/project/wsgi.py
""" WSGI config for labs project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ """ from __future__ import absolute_import, unicode_literals import os from django.core.wsgi import get_wsgi_application #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "labs.settings.dev") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "labs.settings.production") application = get_wsgi_application()
production.py の 修正
production.py にALLOWED_HOSTS
と、SECRET_KEY
を
最低限動作させる
- /var/www/xxx/project/project/production.py
# host 名と ipアドレスを指定しておく ALLOWED_HOSTS = ["www.example.com","xxx.xxx.xxx.xxx"] SECRET_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
SECRET_KEY
が未設定だと、 以下の エラーが 発生します。 raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
DB作成
Postgress 上に
- ユーザーと
データベースを 作成 別途、CREATE ROLE project_usr WITH PASSWORD 'password' WITH LOGIN; CREATE DATABASE project_db OWNER project_usr ENCODING 'UTF8' TEMPLATE template0;
pg_hba.conf
を変更して、 パスワード認証を 行う 必要が あります。
base.py の データベース設定を 変更
base.py には、
- /var/www/xxx/project/project/base.py
DATABASES = { "default": { # Add "postgresql_psycopg2", "mysql", "sqlite3" or "oracle". "ENGINE": "django.db.backends.postgresql_psycopg2", # "ENGINE": "django.db.backends.", # DB name or path to database file if using sqlite3. "NAME": "project_db", # Not used with sqlite3. "USER": "project_usr", # Not used with sqlite3. "PASSWORD": "password", # Set to empty string for localhost. Not used with sqlite3. "HOST": "", # Set to empty string for default. Not used with sqlite3. "PORT": "", } }
psyconpg2 の インストール
wagtail をpsyconpg2
は
python3.6 -m pip install psycopg2
migration と createsuperuser を 実行
migration を
python3.6 manage.py migrate python3.6 manage.py createsuperuser
Apache と 連携する
mod_wsgiの
インストール
CentOS 7 でyum install できるのは、 Python 2の mod_wsgi です。
Python 3 のmod_wsgiは、 pip で インストールします。 以下、python3.6 -m pip install mod_wsgi
mod_wsgi が インストールされました。 /usr/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
wsgi.confの
作成 LoadModule wsgi_module /usr/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so WSGISocketPrefix run/wsgi WSGIRestrictStdout Off # これは、RestAPI 稼働のための設定なので、稼働させる必要がなければ不要 WSGIPassAuthorization On # Apache のLang 設定はそのままで、lang=ja_JP.utf8 で指定 日本語URLでも動作させるため WSGIDaemonProcess project_precess user=apache group=apache python-path=/var/www/xxx/project:/usr/lib64/python3.6/site-packages lang=ja_JP.utf8 WSGIProcessGroup project_precess WSGIApplicationGroup %{GLOBAL} WSGIScriptAlias / /var/www/xxx/project/project/wsgi.py process-group=apache application-group=%{GLOBAL} <Directory "/var/www/xxx/project"> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> # static ディレクトリのマッピング Alias /static /var/www/xxx/project/static/ <Directory "/var/www/xxx/project/static/"> Options Indexes MultiViews FollowSymLinks AllowOverride all Order deny,allow Allow from all </Directory> ~
Apacheの
再起動
Apache を再起動して、 設定を 反映させます。 apachectl restart
これで、
デフォルトの Indexページを 書き換える
デフォルトだと、
すでに
- ページの
格納先
/var/www/xxx/project/home/templates/home/home_page.html
最低限の
セキュリティ設定、
気が
以上です。
いろいろ
インストールしているので、 この 状態は 入りすぎでは あります。 ↩
コメント