I have looked through numerous tutorials and posts related to Apache and Django on Windows to try to solve my issue. I can run the Django project via the development server and know that my Apache install is working. I know that my issue resides in the configuration of Apache to get it to work with Django. My configuration is shown below. I have made sure that the server project folder is accessible to Everyone with read and execute permissions. I have tried setting the paths with the “C:” and without. Setting the server’s filesystem directory access to “Require all granted” (not recommended) does not help. What am I missing?
Django settings.py
ALLOWED_HOSTS = ['*']
WSGI_APPLICATION = 'INDmain.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
httdp.conf
Include conf/extra/httpd-vhosts.conf # "#" is removed from start of line.
LoadFile "c:/users/user/appdata/local/programs/python/python36/python36.dll"
LoadModule wsgi_module "c:/users/user/appdata/local/programs/python/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/user/appdata/local/programs/python/python36"
WSGIScriptAlias / "C:/INDmain/main/wsgi.py
WSGIPythonPath "C:/INDmain"
<Directory "C:/INDmain/main">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
Alias "/" "C:/INDmain/main"
<Directory "C:/INDmain/main">
Require all granted
</Directory>
Alias "/static" "C:/INDmain/static"
<Directory "C:/INDmain/static">
Require all granted
</Directory>
</VirtualHost>
2
Answers
After getting this up and running in a Docker container running Ubuntu, I was able to get my Windows version to work after copying the project into a directory under the Apache directory and making some configuration changes for the new location. Final configuration files are below.
Web site/project layout
Django settings.py
httdp.conf
httpd-vhosts.conf
Granted I only implement on Linux, so the following may not be helpful, but my standard approach would be to create a
sitename_co_uk.conf
file within/etc/apache2/sites-available
The following would be the content of the file:
This means I have my site actually in the directory
/var/www/sitename'. This directory will contain a virtual environment in
envand the
manage.pyfile. My
settings.py,
wsgi.pyetc are within the sub-directory
core`.This is enabled using
a2ensite sitename_co_uk.conf
.It should work in a similar fashion on Windows.