I am new to web frameworks and I have designed small website using DJango-3.1.7.

I am trying to deploy DJango website on Apache server in Windows 10 platform but it seems something not correct or I missed out it. If anyone could help with this we be precious for me.

I have configured virtual environment for this application

Problem:
--------

Getting error PYTHONHOME = (not set) PYTHONPATH = (not set)

> 
> error.log
> 
> 
> 

```
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\Apache24\\bin\\httpd.exe'
  sys.base_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
  sys.base_exec_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
  sys.executable = 'C:\\Apache24\\bin\\httpd.exe'
  sys.prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
  sys.exec_prefix = 'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38'
  sys.path = [
    'C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
    '.\\DLLs',
    '.\\lib',
    'C:\\Apache24\\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 0x00002838 (most recent call first):
<no Python frame>
[Sat Jun 26 21:56:47.558067 2021] [mpm_winnt:crit] [pid 5344:tid 780] AH00419: master_main: create child process failed. Exiting.

```

> 
> etc/hosts
> 
> 
> 

```
127.0.0.2    stack-hack.com

```

> 
> httpd.conf
> 
> 
> 

```
    LoadFile "c:/users/hp/appdata/local/programs/python/python38/python38.dll"
    LoadModule wsgi_module "e:/Code-Stack/stack-hack/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
    WSGIPythonHome "e:/Code-Stack/stack-hack"
    WSGIPythonPath "e:/Code-Stack/stack-hack/Lib/site-packages"

    <VirtualHost *:80>
    ServerAlias www.stack-hack.com
    ServerName stack-hack.com
    ServerAdmin info@admin.com
    WSGIScriptAlias / "E:/Code-Stack/Stack-Hack/src/stackhack/wsgi.py"
    <Directory "E:/Code-Stack/Stack-Hack/src/stackhack">
        <Files wsgi.py>
        Require all granted
        </Files>
    </Directory>

    Alias /static/ "E:/Code-Stack/Stack-Hack/src/static/"
    <Directory "E:/Code-Stack/Stack-Hack/src/static">
        Require all granted
    </Directory>

    ErrorLog "E:/Code-Stack/Stack-Hack/logs/apache.error.log"
    CustomLog "E:/Code-Stack/Stack-Hack/logs/apache.custom.log" common
    </VirtualHost>

```

> 
> wsgi.py
> 
> 
> 

```
    import os
    import sys
    from django.core.wsgi import get_wsgi_application
    from pathlib import Path

    path_home = str(Path(__file__).parents[1])
    if path_home not in sys.path:
        sys.path.append(path_home)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'

    application = get_wsgi_application()

```

Project Structure
-----------------

```
Stack-Hack  [Virtual env]
- Lib
- Scripts
+ src
  - home
  - media
  + stackhack
    - asgi.py
    - settings.py
    - urls.py
    - wsgi.py
  - static
  - manage.py
- pyvenv.cfg

```

Workaround I did:

---

All other django settings are ok and working fine. I have followed various blog post for configuration of Apache Server

1. <https://montesariel.com/blog/post-3>
2. <https://www.codementor.io/@aswinmurugesh/deploying-a-django-application-in-windows-with-apache-and-mod_wsgi-uhl2xq09e>