FlaskAppDeployment: Difference between revisions
Jump to navigation
Jump to search
Line 59: | Line 59: | ||
= Configure Apache = | = Configure Apache = | ||
== Install WSGI == | == Install WSGI == | ||
< | <source> | ||
$ sudo apt-get install libapache2-mod-wsgi-py3 | $ sudo apt-get install libapache2-mod-wsgi-py3 | ||
</ | </source> | ||
= Deploy Hello World = | = Deploy Hello World = |
Revision as of 02:12, 15 August 2023
First runthrough based on: https://www.rosehosting.com/blog/how-to-install-flask-on-ubuntu-22-04-with-apache-and-wsgi/
Install Apache
sudo systemctl status apache2
Already installed - skipping this section.
HTTP
TLS
Install Python / PIP
$ python --version
$ pip --version
Already installed, skipping this section.
Create Python Virtual Enviroment (Venv) for Flask
$ cd /opt/cryptopunk
$ mkdir -p flask/reddit-oauth2/
$ cd flask/reddit-oauth2/
$ python3 -m venv flask-venv
Install Flask
$ cd /opt/cryptopunk/flask/reddit-oauth2
$ source flask-venv/bin/activate
After sourcing the venv activate script, your pip and python ops will occur within the virtual environment, without wrecking up the system-wide Python environment.
Shell prompt should look like:
(flask-venv) user@host:/opt/cryptopunk/flask/reddit-oauth2$
$ pip install flask
Test Install
/opt/cryptopunk/flask/reddit-oauth2/app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello World'
CLI
$ export FLASK_APP=app.py
$ flask run --host=0.0.0.0
Then hit it with a browser: http://localhost:5000/
Control-C to quit the app, then
$ deactivate
to exit the venv.
Configure Apache
Install WSGI
$ sudo apt-get install libapache2-mod-wsgi-py3