Deploy Flask Application to Apache Webserver

  • Install mod_wsgi

sudo apt-get install libapache2-mod-wsgi

  • Enable wsgi module

sudo a2enmod wsgi

sudo systemctl restart apache2

  • Create .wsgi file with below content

from yourapp import app as application

  • Configure a new site in Apache2
<VirtualHost 127.0.0.1:80>
    ServerName site.api

    WSGIDaemonProcess site user=www-data group=www-data threads=5 home=/var/www/site
    WSGIScriptAlias / /var/www/site/app.wsgi

    <Directory /var/www/site>
        WSGIProcessGroup site
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>

    WSGIPassAuthorization On

</VirtualHost>
  • Enable the site and reload Apache2