Page 1 of 1

[Solved] WSGI with Python3 for Django

Posted: Tue Feb 26, 2019 4:35 pm
by neyder
Hi i was needing to use a django app inside a client, so i worked this beacuse official doc and files doesn't work.

This is a first commit, but works swiftly.

This files are meant to enable WSGI support on a Debian or Ubuntu.

Install wsgi apache module

Code: Select all

sudo apt-get install libapache2-mod-wsgi-py3
a2enmod wsgi
Download wsgi template

Code: Select all

cd /usr/local/vesta/data/templates/web
wget https://gitlab.com/neyder/vestacp-wsgi/-/archive/master/vestacp-wsgi-master.tar.gz \
   -O- | sudo tar xzvf - --strip-components=1
Create new package or set wsgi as apache template in the existing package
Add new user and assing him package with wsgi template
Add new domain and check the result

Hints

This is for Python3.
You should create a venv in private dir inside your web domain.
Your project should be alogside venv named as domain_name.

Code: Select all

private
├── name.domain.tld
└── venv
wsgi.py script is inside PROJECTAPP directory

Code: Select all

   private/
   └── name.domain.tld
       ├── manage.py
       └── PROJECTAPP
           └── wsgi.py
you can rename PROJECTAPP with

Code: Select all

sudo sed -i 's/PROJECTAPP/{change_this}/' conf/web/name.domain.tld.apache2.conf
sudo sed -i 's/PROJECTAPP/{change_this}/' conf/web/name.domain.tld.apache2.ssl.conf
this was tested using a django project.

If you want to help this is the repo :

https://gitlab.com/neyder/vestacp-wsgi

Re: [Solved] WSGI with Python3 for Django

Posted: Fri Mar 01, 2019 6:02 pm
by realjumy
This is fantastic. I'm going to try to figure out how to do the same with RHEL / Centos.

So far:

Code: Select all

yum install python26 uwsgi uwsgi-plugin-python36
Then the template that you provided doesn't work in RHEL / Centos. I tried using one that I found after a bit of Googling (https://itproffi.ru/zapusk-proektov-django-v-vestacp/) but with that, I always get the same message: "Error: httpd restart failed". I also think there's an error (although it is probably not the cause of the error) in the wsgi.sh, as it is trying to add the .ru domain to the condition in:

Code: Select all

RewriteCond %{HTTP_HOST} ^www.$2\.ru\$ [NC]

Re: [Solved] WSGI with Python3 for Django

Posted: Mon Mar 04, 2019 12:12 am
by realjumy
I think I will never know how to do it, since I'm not using Centos anymore... :/

Re: [Solved] WSGI with Python3 for Django

Posted: Fri Mar 22, 2019 5:14 pm
by neyder
realjumy wrote:
Mon Mar 04, 2019 12:12 am
I think I will never know how to do it, since I'm not using Centos anymore... :/
So you moved on to Debian/ubuntu side?
realjumy wrote:
Fri Mar 01, 2019 6:02 pm
the wsgi.sh, as it is trying to add the .ru domain to the condition in:

Code: Select all

RewriteCond %{HTTP_HOST} ^www.$2\.ru\$ [NC]
Yeah, that's because it is only for a specific domain, not using VESTA variables and so, take a look at my code.

Should try Vesta on RHEL/CEntOS but not having time this days.

Re: [Solved] WSGI with Python3 for Django

Posted: Sun Mar 24, 2019 8:33 pm
by realjumy
neyder wrote:
Fri Mar 22, 2019 5:14 pm
realjumy wrote:
Mon Mar 04, 2019 12:12 am
I think I will never know how to do it, since I'm not using Centos anymore... :/
So you moved on to Debian/ubuntu side?
realjumy wrote:
Fri Mar 01, 2019 6:02 pm
the wsgi.sh, as it is trying to add the .ru domain to the condition in:

Code: Select all

RewriteCond %{HTTP_HOST} ^www.$2\.ru\$ [NC]
Yeah, that's because it is only for a specific domain, not using VESTA variables and so, take a look at my code.

Should try Vesta on RHEL/CEntOS but not having time this days.
I found Centos easier and more robust for servers, but for a series of reasons I stopped using it. I might return to use Centos very soon, I will try again then.

Re: [Solved] WSGI with Python3 for Django

Posted: Fri Apr 19, 2019 4:51 pm
by realjumy
I'm still having problems with this.

Trying to set up a brand new server, I always get the same error when adding a domain: "Error: apache2 restart failed".

I really want to set up a Django site in my server, but I can't manage to make it work... :/ What a pity.

Re: [Solved] WSGI with Python3 for Django

Posted: Sat Oct 12, 2019 2:19 am
by neyder
There is a new commit on this:

For more info:
https://gitlab.com/neyder/vestacp-wsgi/merge_requests/1