
Deploy Djnago on windows using Xampp
Deploy django on apache in Linux is quite easy (you can check my other post for it), but what about deploy on windows?well safe to say it is a little bit challenging, I checked django website tutorial and other tutorial out there but there where no luck,but finally I found the solution.If you like me ,faced with problem to do this just follow this 7 steps and enjoy you dajngo site hosted by xampp.
Step 0:
Just to make sure that you have already installed:
- xampp (or wampp, if you are using wampp the configuration might be quite different)
- python
- django
and make sure that your project already have a virtual environment, and you copied your project folder into C:\xampp\htdocs.
also you might need windows 10 sdk installed.
Step 1:
first we should set mod wsgi apache rootdir to our xampp apache directory , so in you cmd type:
set “MOD_WSGI_APACHE_ROOTDIR=c:\xampp\apache”
Step 2:
activate your project environment
Step 3:
In your virtual environment type:
pip install mod_wsgi
Step 4:
then type this:
mod_wsgi-express module-config
the output result should be something like this:
LoadFile “c:/python37–32/python37.dll”
LoadModule wsgi_module “c:/python37–32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd”
WSGIPythonHome “c:/python37–32”
Step 5:
open http.conf file and copy to LoadFile and LoadModule from previous step on it
Step 6:
copy this lines in http.conf too:
#path to wsgi.py file #the first “/ “ indicates the root url
WSGIScriptAlias / “C:/xampp/htdocs/your_project_folder/your_project/wsgi.py”
#the one that you get from step 4
WSGIPythonHome “c:/python37–32”
#website path
WSGIPythonPath “C:/xampp/htdocs/your_project_folder”
#directory of website
<Directory “C:/xampp/htdocs/your_project_folder/your_project”>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Step 7:
Restart your xampp and enjoy :)
Notice:
make sure that inside your setting.py you have debug = False and you entered your host address inside allowed host.
Short Notice:
if you have debug = false and you forget your allowed host empty you will get error 400, also if you have debug = False then when you try to enter your api path you will get 404 error for security.
Possible error:
1. Step#3 , may show some problem related to visual studio:
ERROR MICROSOFT VISUAL C++ 14.0 IS REQUIRED
It seems that you need windows 10 sdk installed in order to install mod_wsgi
More info: https://www.scivision.co/python-windows-visual-c++-14-required/
2. Step#4: there may be some error like this :
Traceback (most recent call last):
File “c:\python37–32\lib\runpy.py”, line 193, in _run_module_as_main
“__main__”, mod_spec)
File “c:\python37–32\lib\runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “C:\Python37–32\Scripts\mod_wsgi-express.exe\__main__.py”, line 5, in <module>
File “c:\python37–32\lib\site-packages\mod_wsgi\server\__init__.py”, line 25, in <module>
from . import apxs_config
File “c:\python37–32\lib\site-packages\mod_wsgi\server\apxs_config.py”, line 27
LIBEXECDIR = ‘c:\xampp\apache/lib’
^
SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2–4: truncated \xXX escape
Just go to : “c:\python37–32\lib\site-packages\mod_wsgi\server\apxs_config.py” and edit line 27 like this :
LIBEXECDIR = r’c:\xampp\apache\lib’