Skip to content

Setting up a Flask app on Ubuntu

These notes outline how to set up a minimal Flask application on Ubuntu 18.04 using Python 3.6 and Apache 2.4 using WSGI to communicate between the Web server and the application.

As with any configuration task, there are always alternatives. The instructions in this section make use of the default Python packages for Ubuntu, for example. The Flask tutorial describes a different configuration using the Anaconda Python distribution.

Overview

Eventually, we will have an Apache Web server which receives all incoming http requests. It will then use the WSGI configuration to pass the request to the Flask application for handling as illustrated in the schematic below. Each element in the chain needs to be installed and configured.

Overview

We assume that the following decisions have been taken:

  • The application will use a Python virtual environment
  • The application and the virtual environment will be in a shared location
  • A directory /usr/local/env will contain all shared locations
  • Application code will be kept separate from the environment code
  • The name of the application is myApp
  • The fully qualified domain name is www.myapp.com

We should end up with the following directory structure:


    /usr/local/env/myApp
                    ├── myapp.wsgi
                    ├── app/
                    └── venv/

myapp.wsgi is the file that Apache will use to communicate with the application

app/ is the directory where the application code goes

venv/ is the directory that contains the virtual Python environment