Deploying a Flask web app
This how-to guide will, as an example, show how to deploy a Flask web application, but it will also be helpful (to varying degrees) for other frameworks. It is currently a WORK IN PROGRESS.
Assume the app consists of, among other things, a python file called
main.py which contains the global variable
app, referring to the
Setting up the virtual environment
Once you have your app on the appropriate virtual machine, the first step is to create a virtual environment.
Make sure you are in your project folder and run the command
python3 -m venv env.
You can now activate this environment by running
source env/bin/activate and deactivate it by running
With the environment activated, install any Python modules required for your app.
If uWSGI is not installed on the virtual machine, it will need to be installed. If you do not have permissions to do so you may have to ask someone who does.
Now, pick a port number which is not already in use on the machine. For this tutorial, we will use
You need a uWSGI ini file; the name is not important so we will call it
uwsgi.ini. It should have the following text (being sure to replace the main python file name, the name of the
Flask object, and port number, if necessary):
[uwsgi] strict = true processes = 4 master = true die-on-term = true module = main:app virtualenv = env http-socket = 0.0.0.0:8000