Search code examples
djangoamazon-ec2django-deploymentdjango-dev-serverdjango-hosts

How to run django app on windows server ec2 instance with mysql database and costum domain


I have Copied my files to the server and also setup the domain in the route 53 and also installed the xampp server now When i try starting the server with the command Python manage.py runserver 0.0.0.0:80 it gives me the following error Error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

but when i visit the domain it autmatically redirected to domian.com/dashboard/ and there is all the xampp and apache etc stuff

i tried to run it with out specifying the ip and port the it redirects to the domian/dashboard i want this to use the xampp server for mysql and run on the domain


Solution

  • it seems you're using the the in-built Django webserver that is meant for development purposes but not the best for production follow the steps below Deploy Django Applications on windows server using XAMPP

    Prerequisite: 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”>

    Require all granted

    Step 7:

    Restart your xampp and enjoy

    You may also find more details on this post