How to embed mod_wsgi into Apache on Python Windows

Download mod_wsgi

First, from Unofficial Windows Binaries for Python Extension Packages, select the wheel file (.whl), which is one of the Python archive formats. to download

There are several types of files, but the ones that are downloaded are

mod_wsgi-[mod_wsgi version]+ap[apache version]vc[Visual Studio compiler version]-cp[Python version]-cp[Python version]m-win[OS bits].whl

Files that match For example, if you try to install in the following environment

mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl

Download

Install mod_wsgi

Install mod_wsgi using pip

pip install mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.wh

If successful, mod_wsgi.so will be created under the folder where Python is installed.

C:/Program Files/Python35/mod_wsgi.so

Incorporate mod_wsgi into Apache

Put the created mod_wsgi.so under modules in the folder where Apache is installed.

C:/Programs/Apache24/modules/mod_wsgi.so

Add to httpd.conf

C:/Programs/Apache24/conf/httpd.conf


//Around line 181
LoadModule wsgi_module modules/mod_wsgi.so

In addition, add the following code anywhere

httpd.conf


WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
   <Files wsgi.py>
      Order deny,allow
      Allow from all
   </Files>
</Directory>

If you have the Python modules that your project depends on inside virtualenv, you also need to add the virtualenv site-packages directory to your Python path. To do this, add another line to the Apache configuration

httpd.conf


// X.X is the Python version
WSGIPythonPath /path/to/your/venv/lib/pythonX.X/site-packages

Restart apache

Create a project

You need wsgi.py in your project to use wsgi_mod You can generate a project containing wsgi.py by executing the following command

django-admin startproject [Project name]

By the way, the contents of wsgi.py are as follows

wsgi.py


"""
WSGI config for helloworld 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.9/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "[Project name].settings")

application = get_wsgi_application()

bonus

You have now built an Apache + mod_wsgi environment on Windows, but this configuration does not immediately reflect code changes. One way to solve this is to make MaxRequestsPerChild a small number and create an environment where Apache can be restarted easily. For more information, see modwsgi --ReloadingSourceCode.wiki.

httpd.conf


MaxRequestsPerChild 3

Recommended Posts

How to embed mod_wsgi into Apache on Python Windows
[Kivy] How to install Kivy on Windows [Python]
[Python] How to install OpenCV on Anaconda [Windows]
How to install Python [Windows]
Python 3.6 on Windows ... and to Xamarin.
How to use Dataiku on Windows
How to install pycrypto on Windows
How to deploy django-compressor on Windows
How to install music 21 on windows
How to read pydoc on python interpreter
Python on Windows
Django + Apache with mod_wsgi on Windows Server 2016
How to use Google Assistant on Windows 10
How to erase Python 2.x on Mac.
Memorandum on how to use gremlin python
How to install richzhang / colorization on Windows 10
How to install Apache (httpd) on CentOS7
How to install Apache (httpd) on CentOS8
Run django applications on Windows + Apache + mod_wsgi + services.
Put MicroPython on Windows to run ESP32 on Python
[2020 version] How to install Python3 on AWS EC2
How to embed a variable in a python string
Strategy on how to monetize with Python Java
How to install OpenCV on Jetson Nano Python
How to use Python Kivy ④ ~ Execution on Android ~
How to run MeCab on Ubuntu 18.04 LTS Python
[Python] Memo to translate Matplotlib into Japanese [Windows]
How to quickly install h5py on Windows 10 [Unofficial]
How to live a decent life on 2017 Windows
Run Python on Apache to view InfluxDB data
How to install / verify graphviz on anaconda / windows10
How to install Python
How to install python
python basic on windows ②
Install python on windows
Think about how to program Python on the iPad
How to build a Django (python) environment on docker
How to use Django on Google App Engine / Python
How to enjoy Python on Android !! Programming on the go !!
How to run Django on IIS on a Windows server
How to build a Python environment on amazon linux 2
How to operate Firefox with selenium on Windows Memo
Set-enable Python virtualenv on Windows
[2020.8 latest] How to install Python
Run Openpose on Python (Windows)
Install watchdog on Windows + Python 3.3
python3: How to use bottle (2)
[Python] How to use list 1
How to update Python Tkinter to 8.6
Python + Kivy development on Windows
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
How to register on pypi
How to use Python argparse
Fastest Python installation on Windows
Build Python environment on Windows
Update python on Mac to 3.7-> 3.8
macports Apache, Python 3.3 + non-macports mod_wsgi3.4
Python: How to use pydub
[Python] How to use checkio
Build python environment on windows
How to run Notepad ++ Python