3

I followed this guide exactly: https://www.codementor.io/@aswinmurugesh/deploying-a-django-application-in-windows-with-apache-and-mod_wsgi-uhl2xq09e

I am trying to deploy my django application for the first time ever using mod_wsgi and apache on windows 10.

As mentioned in the guide, I changed a few things:

wsgi_windows.py

activate_this = 'C:/pythonvenv/djangoproj/Scripts/activate'
# execfile(activate_this, dict(__file__=activate_this))
exec(open(activate_this).read(),dict(__file__=activate_this))

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('C:/pythonvenv/djangoproj/Lib/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('C:/pythonstuff/djangoproj')
sys.path.append('C:/pythonstuff/djangoproj/djangoproj')

os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoproj.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangoprog.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

httpd.conf i added the following two lines as given by: mod_wsgi-express module-config

LoadModule wsgi_module "c:/pythonvenv/djangoproj/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win32.pyd"
WSGIPythonHome "c:/pythonvenv/djangoproj"

httpd-vhosts.conf

# Virtual Hosts
#
# virtual SupervisionTool
<VirtualHost *:80>
    ServerName localhost 
    WSGIPassAuthorization On
    ErrorLog "logs/my_application.error.log"
    CustomLog "logs/my_application.access.log" combined
    WSGIScriptAlias /  "C:\pythonstuff\djangoproj\djangoproj\wsgi_windows.py"
    <Directory "C:\pythonstuff\djangoproj\djangoproj">
        <Files wsgi_windows.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static "C:/pythonstuff/djangoproj/djangoproj/static"
    <Directory "C:/pythonstuff/djangoproj/djangoproj/static">
        Require all granted
    </Directory>  
</VirtualHost>
# end virtual SupervisionTool

Everytime i try to run httpd.exe to start my webserver, it gives the following error and then doesn't start. The error is found in the logs.

[Mon Jul 06 19:31:33.542403 2020] [mpm_winnt:notice] [pid 19432:tid 748] AH00455: Apache/2.4.41 (Win32) PHP/7.3.12 mod_wsgi/4.7.1 Python/3.8 configured -- resuming normal operations
[Mon Jul 06 19:31:33.542403 2020] [mpm_winnt:notice] [pid 19432:tid 748] AH00456: Apache Lounge VS16 Server built: Aug  9 2019 16:32:28
[Mon Jul 06 19:31:33.542403 2020] [core:notice] [pid 19432:tid 748] AH00094: Command line: 'httpd.exe -d C:/wamp/bin/apache/apache2.4.41'
[Mon Jul 06 19:31:33.546388 2020] [mpm_winnt:notice] [pid 19432:tid 748] AH00418: Parent: Created child process 17612
Python path configuration:
  PYTHONHOME = 'c:\pythonvenv\djangoproj'
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\wamp\\bin\\apache\\apache2.4.41\\bin\\httpd.exe'
  sys.base_prefix = 'c:\\pythonvenv\\djangoproj'
  sys.base_exec_prefix = 'c:\\pythonvenv\\djangoproj'
  sys.executable = 'C:\\wamp\\bin\\apache\\apache2.4.41\\bin\\httpd.exe'
  sys.prefix = 'c:\\pythonvenv\\djangoproj'
  sys.exec_prefix = 'c:\\pythonvenv\\djangoproj'
  sys.path = [
    'C:\\pythonvenv\\djangoproj\\Scripts\\python38.zip',
    'c:\\pythonvenv\\djangoproj\\DLLs',
    'c:\\pythonvenv\\djangoproj\\lib',
    'C:\\wamp\\bin\\apache\\apache2.4.41\\bin',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00004a24 (most recent call first):
<no Python frame>
[Mon Jul 06 19:31:35.480078 2020] [mpm_winnt:crit] [pid 19432:tid 748] AH00419: master_main: create child process failed. Exiting.

I am not sure what went wrong... can anyone please advise? If not, is there any more hassle-free ways to deploy django on windows 10?

hkcode
  • 309
  • 1
  • 8

0 Answers0