wiki:UoL LAMP HowTo Install Python Flask Applications

UoL LAMP HowTo Install Python Flask Applications

Tags: HowTo Install Pain in the proverbial UoL LAMP Server

This page is for python 3, for python 2 see UoL LAMP HowTo Install Legacy Python Flask Applications

Create Environment

  1. Add python 3 to your path by adding the following line to .profile file in your home directory:
PATH=$PATH:/opt/python3/bin/

You will need to log off and log back in to add the above to your current environment.

  1. Change directory into /local/ and create a virtual environment:
cd /local/ && virtualenv --no-site-packages venv
  1. Activate the virtual environment:
source /local/venv/bin/activate
  1. Download your application from a repository such as GitHub. Go to the application directory and install Flask and the other requirements by running the command:
pip install -r requirements.txt

Apache Setup

  1. Edit the Apache config:
vi /local/apache2/etc/httpd.conf
  1. Amend the values below the comment # List of resources to look for when the client requests a directory to be:
# List of resources to look for when the client requests a directory
DirectoryIndex index.html

WSGIDaemonProcess application user=wwwrun threads=5 python-path=/local/venv/lib/python3.5/site-packages home={{{path to application folder}}}
WSGIScriptAlias / {{{path to application}}}

  1. Edit the Apache modules conf:
vi /local/apache2/etc/loadmodule.conf
  1. Add the following line to the end of the file:
LoadModule      wsgi_module             /opt/python3/lib/mod_wsgi.so
  1. Restart Apache using the command:
sudo /etc/init.d/uol.apache2 restart

Database

  1. One thing to note is that python looks for the mysql socket in the wrong place, so you have to specify where to find it in the connection string. Here is an example connection string:
mysql://{username}:{password}@127.0.0.1/{database}?unix_socket=/db/mysql/mysql.sock

Error: Macro BackLinks(None) failed
'Environment' object has no attribute 'get_db_cnx'

Last modified 6 years ago Last modified on 10/11/18 08:25:04
Note: See TracWiki for help on using the wiki.