Deploy the Django tutorial to IIS ①

Introduction

I'll keep a reminder of how I ran the Django tutorial on IIS on Windows 10.

Reference article

Creating your first Django app, part 1 Host Django on Windows7 + IIS + virtualenv + wfastcgi Running Python (Django) on Windows + IIS HTTP error when opening IIS web page 500.19

table of contents

environment

Python installation

Download the installer from the Official Site. When installing, please install for all users. If it is an individual user installation, it cannot be used by IIS users and cannot be operated. キャプチャ.PNG

キャプチャ000.PNG

Install PostgreSQL

I want to use PostgreSQL, so I will install it.

Download the installer from the Official Site. This time I installed version 13 of Windows x86-64.

Enable IIS (Internet Information Services)

From Control Panel> Programs> Enable or Disable Windows Features Enable Internet Information Services. キャプチャ11.PNG

キャプチャ222.PNG

Computer Management> Services and Applications If the Internet information service has been added, it has been enabled. キャプチャ333.PNG

Django project creation

1. Preparation of development environment

We will create a "web" directory under C: \ Users \ username and work there.

command prompt

C:\Users\username> mkdir web

Install virtualenv

command prompt

C:\Users\username\web> pip install virtualenv

Creating a virtual environment (env)

command prompt

C:\Users\username\web> virtualenv env

Enable virtual environment

command prompt

C:\Users\username\web> env\Scripts\activate

Django installation

command prompt

(env) C:\Users\username\web> pip install Django

wfastcgi installation

command prompt

(env) C:\Users\username\web> pip install wfastcgi

Installation of psycopg2

command prompt

(env) C:\Users\username\web> pip install psycopg2

The result of pip list is below.

command prompt

(env) C:\Users\username\web>pip list
Package    Version
---------- -------
asgiref    3.2.10
Django     3.1.1
pip        20.2.3
psycopg2   2.8.6
pytz       2020.1
setuptools 49.6.0
sqlparse   0.3.1
wfastcgi   3.0.0
wheel      0.35.1

2. Create a project

Follow the Django tutorial to create your project.

command prompt

(env) C:\Users\username\web> django-admin startproject mysite

Check if it works locally

command prompt

(env) C:\Users\username\web>mysite> python manage.py runserver

Go to http://127.0.0.1:8000/ and when the following page is displayed, it's OK. キャプチャ12.PNG

IIS settings

Add site

Add a new site. From Computer Management> Internet Information Services Set the physical path etc. in Site> Add Website.

The physical path sets the folder for your Django project (parent folder, such as manage.py). キャプチャ555.PNG

Added Python handler mapping

Set from Handler Mappings> Add Script Map. The executable file specifies python.exe in the env environment. キャプチャ6.PNG

wfastcgi settings

Unlock to use wfastcgi

(env) C:\Users\username\web\mysite>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
Configuration path"MACHINE/WEBROOT/APPHOST"Section"system.webServer/handlers"Unlocked.

Run wfastcgi enable

(env) C:\Users\username\web\mysite>wfastcgi-enable
Configure configuration changes Commit path"MACHINE/WEBROOT/APPHOST"of"MACHINE/WEBROOT/APPHOST"Section"system.webServer/fastCgi"Applied to
"c:\users\username\web\env\scripts\python.exe|c:\users\username\web\env\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor

Create web.config

Create web.config under the Django project (same directory as manage.py). Set the value of scriptProcessor to the value displayed by wfastcgi-enable.

web.config


<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="PYTHONPATH" value="C:\Users\username\web" />
    <add key="DJANGO_SETTINGS_MODULE" value="mysite.settings" />
  </appSettings>
  <system.webServer>
    <handlers>
        <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\users\username\web\env\scripts\python.exe|c:\users\username\web\env\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
</configuration>

Granting permissions for IIS

Computer Management> Internet Information Services Edit the permissions from My Site (newly created site). Add user [Computer Name \ IIS_IUSRS] on the Security tab

Also, in File Explorer, right-click on the C: \ Users \ username \ web env folder> Properties Also add a user with [Computer name \ IIS_IUSRS].

Operation check

Go to Computer Management> Internet Information Services, select My Site, browse the website and the rocket flies, then the Django site is running. キャプチャ12.PNG

If you get an error

If you get a 0x800700005 error or a 0x8007010b error as shown below, Please check if the file access permission and the Python.exe path set in the handler mapping are appropriate.

Cause: Occurs when the site directory does not have access to the computer name \ IIS_IUSRS Solution: Add permissions for computer name \ IIS_IUSRS キャプチャ12345.PNG

Cause: Occurs when you do not have access to the computer name \ IIS_IUSRS in the Python.exe directory you are using. Solution: Add permissions for computer name \ IIS_IUSRS キャプチャ53.PNG

Next time I will write the procedure to change the database to PostgreSQL: wave:

Recommended Posts

Deploy the Django tutorial to IIS ①
Deploy django project to heroku
Stumble when doing the django 1.7 tutorial
How to check the version of Django
Deploy the Django app on Heroku [Part 2]
Deploy the Django app on Heroku [Part 1]
Django Heroku Deploy 1
Python Django Tutorial (5)
Python Django Tutorial (2)
Python Django Tutorial (8)
Python Django Tutorial (6)
Start Django Tutorial 1
Django Heroku Deploy 2
Python Django Tutorial (7)
Python Django Tutorial (1)
Python Django tutorial tutorial
Python Django Tutorial (3)
Python Django Tutorial (4)
The easiest way to get started with Django
How to print debug messages to the Django console
I referred to it when I got stuck in the django geodjango tutorial (editing)
Python Django tutorial summary
I want to scroll the Django shift table, but ...
Django Polymorphic Associations Tutorial
How to deploy a Django application on Alibaba Cloud
django oscar simple tutorial
[Azure] Deploy locally created ML model to the cloud
Read the xml file by referring to the Python tutorial
Set the form DateField to type = date in Django
unable to import django
[Django] Rename the project
The road to Pythonista
Transit to the update screen with the Django a tag
Django Girls Tutorial Note
update django version 1.11.1 to 2.2
How to run Django on IIS on a Windows server
Kaggle Tutorial Titanic know-how to be in the top 2%
The road to Djangoist
[Django] How to redirect unlogged-in users to the login page
Deploy the management page to production to make maintenance easier.
How to write custom validations in the Django REST Framework
[Django] Pass the user instance authenticated by API to ModelSerializer
How to deploy the easiest python textbook pybot on Heroku
Deploy Django + React from scratch to GKE (1) Backend development --Nginx + Django
How to do the initial setup from Django project creation
Until the start of the django tutorial with pycharm on Windows
Display the time in Django according to the user's region (UTC)
Deploy Django + React from scratch to GKE: Table of Contents
Django Make choices only for the facility you belong to
In Django, how to abbreviate the long displayed string as ....
Django --Overview the tutorial app on Qiita and add features (2)
DJango Memo: From the beginning (more edits to the management screen)
Get started with Django! ~ Tutorial ⑤ ~
Dot according to the image
Deploy Django serverless with Lambda
The road to download Matplotlib
Get started with Django! ~ Tutorial ④ ~
Get started with Django! ~ Tutorial ⑥ ~
Python Django Tutorial Cheat Sheet
Pass text to Django genericview
How to use the decorator