current position:Home>windows10+apache2. 4 + Django deployment

windows10+apache2. 4 + Django deployment

2022-01-31 13:24:13 BGLB

windows10+apache2.4+django Deploy

During deployment , A lot of holes Take notes

Introduction to the environment

  1. python 3.7
  2. apache 2.4.15
  3. django 2.1
  4. windows10

install apache2.4

the latest version apache2.4 : httpd-2.4.51-win64-VS16

  1. Decompress after downloading  picture alt
  2. take Apache24 Copy the folder to your own The installation path I put it directly here C disc C:/Apache24, Because the current online is on C disc Maybe it's for the convenience of installation Let's see what's inside

 picture alt

  1. add to apache environment variable



Environment variables are added directly to the system environment variables , There is no mapping here

  1. The installation to windows service
 #  install 
 httpd -k install -n  The service name 
 #  start-up 
 1. httpd -k start [stop, restart]
 #  perhaps 
 2. net start  The service name 
 Copy code 

There are many ways to start It can also be opened bin In the catalog ApacheMonitor.exe But he won't pop up after double clicking , It will be in the tray in the lower right corner

then Double click the tray icon You can open it It looks like this


If no error is reported during startup , You can open the browser , Visit No accident You can see that It’s Work!

Only this and nothing more , Apache installation is complete

Deploy Django

  1. download mod_wsgi

    Use pip install mod_wsgi.whl file , Use pip Many words You should know

    Why install ? I don't know Be similar to linux Upper uwsgi

    If not installed before , Just do it , If you step on the pit It's necessary to step on more

    mod_wsgi Download address : mod_wsgi download

    Open the link above Search with you python The version corresponds to


    Pay attention here , If you use python A virtual environment Deploy django Words need Install... In a virtual environment ( Virtual environment is recommended )

     #  Enter the virtual environment 
     pip install  Download the mod_wsgi route 
     #  After installation   It's best to see if it's successful 
     pip list | findStr "mod_wsgi"
     Copy code 
  1. modify Apache Default profile C:\Apache24\conf\httpd.conf

    Before the change stay django In the virtual environment need Run it mod_wsgi-express module-config

    After running Three paths will be returned like this

     LoadFile "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python37.dll"
     LoadModule wsgi_module "e:/development/django_project/env/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
     WSGIPythonHome "e:/development/django_project/env"
     Copy code 

    Be sure to generate your own , Don't use my !

    Put the path above Copy To apache In the configuration file also modify Listen and ServerName

     Define SRVROOT "C:/Apache24"   
     ServerRoot "${SRVROOT}"
     #  Here I change it to 9000 
     Listen 9000
     ServerName localhost:9000
     #  load  mod_wsgi
     LoadFile "C:/Users/Administrator/AppData/Local/Programs/Python/Python37/python37.dll"
     LoadModule wsgi_module "e:/development/django_project/env/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
     WSGIPythonHome "e:/development/django_project/env"
     #  Set project path 
     WSGIPythonPath E:\development\django_project
     #  Set up Django In the project wsgi route 
     WSGIScriptAlias / E:\development\django_project\django_project\
     #  Set up wsgi File permissions 
     <Directory E:\development\django_project\django_project>
             Require all granted
     #  Set static file path   Do path mapping 
     Alias /assets E:\development\online\django_project\static
     #  Set static path permissions 
     <Directory E:\development\online\django_project\static>
         AllowOverride None  
         Options None  
         Require all granted  
     Copy code 
  2. restart Apache

    httpd -k resfart

    The above command There is no prompt after running

    net stop apache24

    net start apache24

    The top two There are relevant tips At least I'll tell you Whether the startup is successful or not

    If you fail Just go to C:\Apache24\logs Catalog see dependent error journal

    Okay Back to the point

    Usually at this time If nothing happens There should be an accident !

    my Apache ad locum Can't start , The log is as follows :

    Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings'

    To see this Feel familiar I guess it was before Toss about u Discoid python I have seen

    Because of this encdings yes python A library of its own therefore I'll go to this machine python The path of this library is viewed under the path And added it to In the system environment variable

    however Still can't solve Last It's found This article window2008 Next ,apache+mod_msgi+flask Problems arise , Please help me have a look


    PYTHONHOME="C:\Users\Administrator\AppData\Local\Programs\Python\Python37" PYTHONPATH="C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib"

    And then when we're done Need to restart the machine

    do not know why ????? After I try, I can start

End of deployment

At that time Problems encountered Now I've forgotten , It was the day before yesterday , The brain really doesn't work

Have the time Try again apache Multi site deployment

copyright notice
author[BGLB],Please bring the original link to reprint, thank you.

Random recommended