I searched whole Internet but unable to find a single tutorial to host and run Django site on Virtualmin. There should be atleast one proper guide to install Django site.
It’s a bit of a head ache, at least it was for me. The way I’ve done it was to install mod_wsgi and then through trial and error I followed Django’s docs here:
Once you get mod_wsgi installed, you edit the Apache configuration and add the following (this is from my current setup). Go to Services → Cnfigure (SSL) Website → Edit directives
Be aware, the code below contains paths you need to change according to your needs (the setup is from a subdomain I use for testing things out).
Alias /media/ /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/media/
Alias /static/ /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/static/
WSGIDaemonProcess [[sub.domain.name]] python-home=/home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[venv-folder]] python-path=/home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]
WSGIProcessGroup [[sub.domain.name]]
WSGIPassAuthorization On
<Directory /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/static>
Require all granted
</Directory>
<Directory /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/media>
Require all granted
</Directory>
WSGIScriptAlias / /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/[[django-project-settings-folder]]/wsgi.py
<Directory /home/[[main.domain.name]]/domains/[[sub.domain.name]]/[[folder-containing-django-project]]/[[django-project-settings-folder]]>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
I think this will get you going. Also, if my memory serves right, you need to be careful what mod_wsgi you install i.e. you need to choose the one for Python3
You should do it on your domain conf file, and I think just in one place i.e. either ssl website or regular website.
You should check your apche error log and look for python errors. You’ll certainly see something if mod_wsgi is working at all. Btw, did you configure wsgi.py and Django according to deployment documents?
One thing I noticed, you shouldn’t host your python files in public_html. That’s a very bad practice.
What I’m doing (and I’m not saying you should necessarily do it) is two folders above public_html. One tor the environment and a separate one for the code.
Normally, eveything Django should live above public_html. The settings in apache makes it work as it should.
Other than that, I’m not sure what else I can say…
Hi. Can you share your .conf files(domain conf, file and wsgy.py) please ? I am having some issues in configuration.
Please share your file by changing all your personal stuffs names.
I’m officially on holiday so not anywhere near a computer. The code I pasted initially is literally my domain config regarding mod_wsgi so I’d say keep looking at it and keep trying. I can assure you that domain config works and not on just one site. If in three weeks you don’t get it sorted, leave a line here and I’ll try to help as best as I can.
Hi. Thank you for your kind words and quick helps. With your help, I successfully installed Django on virtualmin. But after making migrations, my app failed to run and showing did you install mysql error. Even I logged in with my user password which is stored in mysql database. So I deleted the project and reinstalled a new project and configured same step and got same mysql install error.
now I decided to ditch the idea and now looking for nodejs deployment.