LoginSignup
0
0

More than 1 year has passed since last update.

WSL + django + mod_wsgiで環境構築の練習を行う

Posted at

はじめに

本番環境の環境構築を行う前に一度WSLで環境構築の練習を行ったのでその方法を残す

前提

  • pyenvを使用してPython or Anacondaをインストールしている
  • pipでdjangoをインストールしている

apacheのインストール

apacheをインストールして起動します。

# インストール
sudo apt install apache2 apache2-dev
# 起動
sudo service apache2 start

起動したらhttp://localhostにアクセスして起動しているか確認する

プロジェクトの作成

djangoのプロジェクトを作成する。
プロジェクトは/home/{UserName}/に作ります。
(今回はRest Frameworkの練習をしていたのでdjango_rest_framework_testとした)

# django-admin startproject {プロジェクトの名前}
django-admin startproject django_rest_framework_test

mod_wsgiのインストール

mod_wsgiをインストールします。

pip install mod_wsgi

インストールしたら以下を実行します

mod_wsgi-express module-config

実行したら以下のようなものが表示されると思います。
これはどこかにコピーしておいてください。

LoadModule wsgi_module "/home/{UserNane}/.pyenv/versions/anaconda3-2021.05/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
WSGIPythonHome "/home/{UserName}/.pyenv/versions/anaconda3-2021.05"

apacheとmod_wsgiの紐づけ

/etc/apache2/apache2.confに追記します。

LoadModule wsgi_module /home/{UserName}/.pyenv/versions/anaconda3-2021.05/lib/python3.8/site-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so
WSGIPythonHome /home/{UserName}/.pyenv/versions/anaconda3-2021.05

WSGIScriptAlias / /home/{UserName}/django_rest_framework_test/django_rest_framework_test/wsgi.py
WSGIPythonPath /home/{UserName}/django_rest_framework_test


<Directory /home/{UserName}/django_rest_framework_test/django_rest_framework_test>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

確認

apache2.confに追記したらapacheを再起動します。

sudo service apache2 restart

再起動後、http://localhostにアクセスしてdjangoの画面が出たら成功です。

0
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
0
0