December 10

Run your Python Flask app with existing Apache server

If you already have an EC2 with Apache, you can use it to run your Python Flask app.
Install and Enable mod_wsgi:
$ sudo apt-get install libapache2-mod-wsgi-py3 python-dev
$ sudo a2enmod wsgi 
Create a Flask app if you don't have one. See my other blog for create / run flask app
Configure and Enable a New Virtual Host:
$ sudo nano /etc/apache2/sites-available/MyFlaskApp.conf
Add the following conf code in MyFlaskApp.conf, (double click to copy it)
Enable the virtual host with the following command:
$ sudo a2ensite MyFlaskApp
Create the .wsgi File
$ cd /var/www/MyFlaskApp
$ sudo nano app.wsgi 
Add the following lines of code to the app.wsgi file:
import sys
import logging
from app import app as application
Restart Apache
$ sudo service apache2 restart 
Send us a message. We will reply as soon as we can.