Djangoの自作アプリを作成し、ネットにアップしたいと思いVPSを借りてデプロイ作業を行なっています。
環境 Ubuntu16.04 Pyhton3.6.4 Django2.0.2
色々なサイト様を拝見し、あと少しでデプロイできそうな感じになっています。(そんな気がします・・・。)
複数のドメインを使用する予定なので、バーチャルホストの設定をしつつのデプロイ作業になっています。
今やり終えたことは
python導入 Django導入 Apache2導入 mod_wsgi導入
までは終えています。
仮想環境は使用していません。
Djangoアプリの場所 /var/www/hoge/hogehoge
以下、設定ファイルです。
pythonの場所 ['', '/root/.pyenv/versions/3.6.4/lib/python36.zip', '/root/.pyenv/versions/3.6.4/lib/python3.6', '/root/.pyenv/versions/3.6.4/lib/python3.6/lib-dynload', '/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages']
/etc/apache2/sites-available/hoge.conf <VirtualHost *:80> ServerName hogeyy.com WSGIDaemonProcess hogeyy.com python-home=/root/.pyenv/versions/3.6.4/ python-path=/var/www/hoge/hogehoge WSGIProcessGroup hogeyy.com WSGIScriptAlias / /var/www/hoge/hogehoge/app/wsgi.py \ process-group=hogeyy.com application-group=%{GLOBAL} Alias /static/ /var/www/hoge/hogehoge/static/ Alias /media/ /var/www/hoge/hogehoge/media/ <Directory /var/www/hoge/hogehoge/static> Require all granted </Directory> <Directory /var/www/hoge/hogehoge/media> Require all granted </Directory> <Directory /var/www/hoge/hogehoge/app> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost>
上記の設定で、ブラウザにて確認しようとしたら以下のエラーが発生しました。
[Tue Aug 14 15:46:10.303186 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] mod_wsgi (pid=20441): Target WSGI script '/var/www/hoge/hogehoge/app/wsgi.py' cannot be loaded as Python module. [Tue Aug 14 15:46:10.303700 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] mod_wsgi (pid=20441): Exception occurred processing WSGI script '/var/www/hoge/hogehoge/app/wsgi.py'. [Tue Aug 14 15:46:10.304015 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] Traceback (most recent call last): [Tue Aug 14 15:46:10.304067 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] File "/var/www/hoge/hogehoge/app/wsgi.py", line 12, in <module> [Tue Aug 14 15:46:10.304139 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] from django.core.wsgi import get_wsgi_application [Tue Aug 14 15:46:10.304193 2018] [wsgi:error] [pid 20441:tid 140562936821504] [remote 34.212.172.251:26708] ImportError: No module named 'django'
参考にさせていただいたサイト
Django + Apache + mod_wsgiでWebサーバを構築してみた
Stackflow
apache2、mod_wsgiを再インストールし直して同じことをやってみましたが、同じ状況です。
sudo apt-get apache2 apache2-dev ↓ pip install mod-wsgi mod-wsgi-httpd
Djangoアプリディレクトリからpython manage.py runserver
を行い動作を確認しましたが、サイトは立ち上がっていました。
デプロイのやり方が間違っているのでしょうか?
初めてのデプロイ作業のためなんとかやりきりたいと考えています。
どなたかご教示いただけると幸いです。
よろしくお願いします。
追記(2018/8/17)
以下、Djangoのインストール情報です。
#pip show django Name: Django Version: 2.0.2 Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design. Home-page: https://www.djangoproject.com/ Author: Django Software Foundation Author-email: foundation@djangoproject.com License: BSD Location: /root/.pyenv/versions/3.6.4/lib/python3.6/site-packages Requires: pytz Required-by: django-debug-toolbar
追記(2018/8/18 0:18)
/etc/apache2/sites-available/hoge.conf 回答いただいた内容を追記 <VirtualHost *:80> ServerName hoge.com WSGIDaemonProcess hoge.com python-home=/root/.pyenv/versions/3.6.4 python-path=/var/www/hoge/hogehoge:/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages WSGIProcessGroup hoge.com WSGIScriptAlias / /var/www/hoge/hogehoge/app/wsgi.py \ process-group=hoge.com application-group=%{GLOBAL} Alias /static/ /var/www/hoge/hogehoge/static/ Alias /media/ /var/www/hoge/hogehoge/media/ <Directory /var/www/hoge/hogehoge/static> Require all granted </Directory> <Directory /var/www/hoge/hogehoge/media> Require all granted </Directory> <Directory /var/www/hoge/hogehoge/app> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost>
0:18現在のエラーメッセージ(以前のエラーメッセージと行数が違うのは、以前のconfファイルにはstatic系のコードが記載されていないため) [Sat Aug 18 00:18:03.199880 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] mod_wsgi (pid=9826): Target WSGI script '/var/www/hoge/hogehoge/app/wsgi.py' cannot be loaded as Python module. [Sat Aug 18 00:18:03.200236 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] mod_wsgi (pid=9826): Exception occurred processing WSGI script '/var/www/hoge/hogehoge/app/wsgi.py'. [Sat Aug 18 00:18:03.200512 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] Traceback (most recent call last): [Sat Aug 18 00:18:03.200572 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] File "/var/www/hoge/hogehoge/app/wsgi.py", line 20, in <module> [Sat Aug 18 00:18:03.200584 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] from django.core.wsgi import get_wsgi_application [Sat Aug 18 00:18:03.200637 2018] [wsgi:error] [pid 9826:tid 140161661003520] [remote 35.171.84.122:33256] ImportError: No module named 'django'
ここまでで行ったこと
sudo service apache2 restart sudo service apache2 stop sudo service apache2 start
回答3件
あなたの回答
tips
プレビュー