-
Notifications
You must be signed in to change notification settings - Fork 2
Setting Up: Flask
Flask was set up on a dedicated m5.large EC2 instance (2 vCPUs, 8GB memory), and served with Apache Server via WSGI.
sudo apt update
sudo apt install apache2
sudo apt install libapache2-mod-wsgi-py3
sudo apt install python3-pip
sudo pip3 install flask
The website lives inside the directory ~/flaskapp
, which is soft-linked to Apache's default web directory.
mkdir ~/flaskapp
sudo ln -sT ~/flaskapp /var/www/html/flaskapp
Test whether the link is working by writing something to the homepage and viewing it via the instance's public IP.
echo "Hello World" > ~/flaskapp/index.html
WSGI is a specification that helps Apache display the dynamic content from our app. We enable it by editing Apache's configuration file.
sudo nano /etc/apache2/sites-enabled/000-default.conf
Add the following text just after the DocumentRoot /var/www/html
line in 000-default.conf
. This specification is for a website that'll live at <public-IP>/flaskapp
.
WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi
<Directory flaskapp>
WSGIProcessGroup flaskapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
Finally, initialize WSGI.
sudo a2enmod wsgi
The web interface is a Flask app served with Apache Server via a WSGI. The app itself is very standard, with
- a Python script translating user input into its corresponding SQL query and retrieving the results
- a single HTML file that displays the results in a plot
The plot is rendered with JavaScript (Chart.js) and website styled with the Bootstrap CSS library.
After any edits to the app or webpage, I needed to restart the server to see the changes.
sudo apachectl restart
[Hint] If the webpage is rendering weird, can check the error log at /var/log/apache2/error.log
.
📬 Create an issue if you have one.
(📝 instructions accurate as of Feb 2020)