Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Web Server
  • Search

Can't get the Flask (python3) site up on the VESTA Apache server Topic is solved

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Post Reply
  • Print view
Advanced search
3 posts • Page 1 of 1
flaskDev
Posts: 3
Joined: Mon Jun 03, 2019 1:23 am

Os: Debian 8x
Web: apache
Can't get the Flask (python3) site up on the VESTA Apache server
  • Quote

Post by flaskDev » Mon Jun 03, 2019 2:36 am

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:

Code: Select all

# a2dissite 000-default.conf
# a2ensite appname.conf
# service apache2 reload
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.
Last edited by flaskDev on Wed Jun 26, 2019 2:12 pm, edited 1 time in total.
Top

flaskDev
Posts: 3
Joined: Mon Jun 03, 2019 1:23 am

Os: Debian 8x
Web: apache
Re: Can't get the Flask (python3) site up on the VESTA Apache server
  • Quote

Post by flaskDev » Mon Jun 03, 2019 6:13 pm

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.
Top

flaskDev
Posts: 3
Joined: Mon Jun 03, 2019 1:23 am

Os: Debian 8x
Web: apache
Re: Can't get the Flask (python3) site up on the VESTA Apache server
  • Quote

Post by flaskDev » Thu Jun 06, 2019 12:30 am

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

Code: Select all

$ apt install libapache2-mod-wsgi-py3
In case the mod is not automatically enabled then

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
And if virtual environment for python3 is not installed then

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
Optional for confirming proper flask installation:

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
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

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
Top


Post Reply
  • Print view

3 posts • Page 1 of 1

Return to “Web Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password