I\'ve got a basic \"hello world\" Flask app running.
I\'m on Ubuntu 14.04, using Apache 2.4. I\'ve installed mod_wsgi.
I\'ve created a ~/web/piFlask/
I started running python3.5.2 with flask 0.12 in a venv on a Ubuntu 16.04 (virtual machine).
@Graham pointed out activating the the venv from the WSGI script file is not the preferred way. More info here: http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
Just for anyone else looking for info on this I'm putting all your steps together:
Note: my app name is blazing, path ~/jan/blazing. Replace them with your own.
sudo apt install python3-pip
sudo apt-get install python3-venv
python3 -m venv ~/blazing/venv
source /home/jan/blazing/venv/bin/activate
pip3 install --upgrade pip
pip3 install Flask
sudo apt-get install apache2-dev
(venv) pip3 install mod_wsgi
(venv) sudo venv3/bin/mod_wsgi-express install-module
OUTPUT:
LoadModule wsgi_module "/usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so"
WSGIPythonHome "/home/jan/blazing/venv"
sudo vim /etc/apache2/mods-available/wsgi_express.load
ADD: LoadModule wsgi_module "/usr/lib/apache2/modules/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so"
sudo vim /etc/apache2/mods-available/wsgi_express.conf
ADD:
WSGIPythonHome "/home/jan/blazing/venv"
WSGIPythonPath /home/jan/blazing/venv/lib/python3.x/site-packages
then
sudo a2enmod wsgi_express
vim /home/jan/blazing/project/flaskapp.wsgi
ADD:
import os, sys
PROJECT_DIR = '/home/jan/blazing' sys.path.insert(0, PROJECT_DIR)
activate_this = os.path.join( PROJECT_DIR, 'venv/bin', 'activate_this.py' )
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this)
from piFlask import app as application application.debug = True
and
vim /etc/apache2/sites-available/flask.conf
ADD:
WSGIDaemonProcess flaskProcess user=www-data group=www-data threads=5
WSGIScriptAlias /flask /home/jan/blazing/project/flaskapp.wsgi
ErrorLog ${APACHE_LOG_DIR}/error_flask.log #you can see the errors here..
CustomLog ${APACHE_LOG_DIR}/access_flask.log combined
WSGIProcessGroup flaskProcess
WSGIApplicationGroup %{GLOBAL}
Require all granted
Or if you have other sites running and would like to have flask as one of the Virtual hosts, you can use this conf file:
ServerName flask.ubuntuws
ErrorLog ${APACHE_LOG_DIR}/error_flask.log
CustomLog ${APACHE_LOG_DIR}/access_flask.log combined
WSGIDaemonProcess flaskProcess user=www-data group=www-data threads=5
WSGIScriptAlias / /home/jan/blazing/project/flaskapp.wsgi
WSGIProcessGroup flaskProcess
WSGIApplicationGroup %{GLOBAL}
Require all granted
and make sure your PROJECT_DIR in flaskapp.wsgi points to your PROJECT_NAME.py.
enable the virtual site and reload apache:
lastly:
sudo a2ensite flask.conf
sudo service apache2 reload