User Tools

Site Tools


howto:web_app

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
howto:web_app [2023/03/13 20:48] – created oxrushhowto:web_app [2023/03/13 21:12] – Add venv and uwsgi sections oxrush
Line 3: Line 3:
 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**. 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 ''Flask'' object.
  
 +===== 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 ''deactivate''.
 +
 +With the environment activated, install any Python modules required for your app.
 +
 +===== uWSGI =====
 +
 +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 ''8000''.
 +
 +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):
 +<code>
 +[uwsgi]
 +strict = true
 +processes = 4
 +master = true
 +die-on-term = true
 +module = main:app
 +virtualenv = env
 +http-socket = 0.0.0.0:8000
 +</code>
 +
 +===== Testing =====