We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Can't get the Flask (python3) site up on the VESTA Apache server Topic is solved
Can't get the Flask (python3) site up on the VESTA Apache server
I've been at it for the last three days and don't seem to be getting anywhere.
I was able to run the Flask app on a locally installed Apache server. It consists of 3 files: appname.py, appname.wsgi & appname.conf. On the local Apache server the ".py" and ".wsgi" are in /var/www directory and the ".conf" in /etc/apache2/sites-available. All I had to do for the flask site to run were the following three commands:
Btw, its all python3, on the local as well on the VESTA server, and the corresponding mod_wsgi is also installed and enabled. I followed https://vestacp.com/docs/#how-to-enable ... ian-ubuntu as discribed, and also again with the following modifications viewtopic.php?t=10867 for the wsgi templates.
So what I'm basically asking is how do I mirror the above steps? Which directories do /var/www and /etc/apache2/sites-available correspond to? Does the # a2ensite appname.conf command has any effect in VESTA, is it overridden by VESTA somehow? Any helpful feedback is really appreciated.
I was able to run the Flask app on a locally installed Apache server. It consists of 3 files: appname.py, appname.wsgi & appname.conf. On the local Apache server the ".py" and ".wsgi" are in /var/www directory and the ".conf" in /etc/apache2/sites-available. All I had to do for the flask site to run were the following three commands:
Code: Select all
# a2dissite 000-default.conf
# a2ensite appname.conf
# service apache2 reload
So what I'm basically asking is how do I mirror the above steps? Which directories do /var/www and /etc/apache2/sites-available correspond to? Does the # a2ensite appname.conf command has any effect in VESTA, is it overridden by VESTA somehow? Any helpful feedback is really appreciated.
Last edited by flaskDev on Wed Jun 26, 2019 2:12 pm, edited 1 time in total.
Re: Can't get the Flask (python3) site up on the VESTA Apache server
I just go it up and running!
If there's any interest I could post a full how-to of the process. I might just do one anyway in the next couple of days.
If there's any interest I could post a full how-to of the process. I might just do one anyway in the next couple of days.
Re: Can't get the Flask (python3) site up on the VESTA Apache server
HOWTO for running Flask on VestaCP
Tested on Debian 9.9 with Python 3.5.3
(If you're not 'root' then put a 'sudo' before most commands)
- - -
1. Installing python3 version of mod_wsgi for Apache
In case the mod is not automatically enabled then
2. Placing the wsgi_flask templates for VestaCP
Downloading the three wsgi_flask.* files from https://github.com/anton-bozhina/vestac ... n-template and placing them in /usr/local/vesta/data/templates/web
3. Following only the steps 3, 4 and 5 of the VestaCP documentation https://vestacp.com/docs/#how-to-enable ... ian-ubuntu
(the first two steps do not apply for Python3 and Flask)
Here only as an example to be used in the following steps:
4. Figuring out all the relevant directories and files
Location of the Apache config file for the newly created domain:
/home/%user%/conf/web/%domain%.apache2.conf
There is a line WSGIScriptAlias / /home/%user%/web/%domain%/public_html/app.wsgi. This is the location of the python script to be passed to Apache through WSGI.
(wsgi_flask.sh auto-creates "app.wsgi" file in the above location)
(If, for some reason, the name of "app.wsgi" need to be changed then the Apache .conf file should be updated accordingly)
There is a line starting with WSGIDaemonProcess .... In there look for python-home=/home/%user%/web/%domain%/private/venv. That's where WSGI will look for the python virtual environment, which does not exist yet and should be set up.
Then look for python-path=/home/%user%/web/%domain%/public_html. That's the location where python main python application is located.
(wsgi_flask.sh auto-creates "app.py" file in this location as well)
5. Setting up python3 virtual environment and installing flask in there
In case pip for python3 is not installed then
And if virtual environment for python3 is not installed then
Optional for confirming proper flask installation:
6. Fixing app.wsgi file
In the auto-generated file app.wsgi there were three lines that i had to comment out. All of the 3 lines have "activate_this" in them.
In the line .../python3.7/... please adjust accordingly, if not using python 3.7.
(In my case, I changed it to .../python3.5/..., and deleted the three lines)
7. Reloading the Apache Web Server after everything is set up
In case of ERROR 500 while accessing the site (which I myself had to deal with), the following command is invaluable to track down errors
- - -
Here is the location of config and log files in VestaCP
https://vestacp.com/docs/#config-log-lo ... ian-ubuntu
Tested on Debian 9.9 with Python 3.5.3
(If you're not 'root' then put a 'sudo' before most commands)
- - -
1. Installing python3 version of mod_wsgi for Apache
Code: Select all
$ apt install libapache2-mod-wsgi-py3
Code: Select all
$ a2enmod wsgi
2. Placing the wsgi_flask templates for VestaCP
Downloading the three wsgi_flask.* files from https://github.com/anton-bozhina/vestac ... n-template and placing them in /usr/local/vesta/data/templates/web
3. Following only the steps 3, 4 and 5 of the VestaCP documentation https://vestacp.com/docs/#how-to-enable ... ian-ubuntu
(the first two steps do not apply for Python3 and Flask)
Here only as an example to be used in the following steps:
- the newly created Package in VestaCP is named: **wsgi_flask**
- the newly created user with Package wsgi_flask: **%user%**
- the newly created domain with Web Template wsgi_flask: **%domain%**
4. Figuring out all the relevant directories and files
Location of the Apache config file for the newly created domain:
/home/%user%/conf/web/%domain%.apache2.conf
There is a line WSGIScriptAlias / /home/%user%/web/%domain%/public_html/app.wsgi. This is the location of the python script to be passed to Apache through WSGI.
(wsgi_flask.sh auto-creates "app.wsgi" file in the above location)
(If, for some reason, the name of "app.wsgi" need to be changed then the Apache .conf file should be updated accordingly)
There is a line starting with WSGIDaemonProcess .... In there look for python-home=/home/%user%/web/%domain%/private/venv. That's where WSGI will look for the python virtual environment, which does not exist yet and should be set up.
Then look for python-path=/home/%user%/web/%domain%/public_html. That's the location where python main python application is located.
(wsgi_flask.sh auto-creates "app.py" file in this location as well)
5. Setting up python3 virtual environment and installing flask in there
In case pip for python3 is not installed then
Code: Select all
$ apt install python3-pip
Code: Select all
$ apt install python3-venv
Code: Select all
$ cd /home/%user%/web/%domain%/private
$ python3 -m venv venv
$ . /venv/bin/activate
(venv) $ pip install flask
Code: Select all
(venv) $ pip freeze
Code: Select all
(venv) $ deactivate
6. Fixing app.wsgi file
In the auto-generated file app.wsgi there were three lines that i had to comment out. All of the 3 lines have "activate_this" in them.
In the line .../python3.7/... please adjust accordingly, if not using python 3.7.
(In my case, I changed it to .../python3.5/..., and deleted the three lines)
7. Reloading the Apache Web Server after everything is set up
Code: Select all
$ service apache2 reload
Code: Select all
$ tail –f /var/log/apache2/domains/%domain%.error.log
Here is the location of config and log files in VestaCP
https://vestacp.com/docs/#config-log-lo ... ian-ubuntu