Skip to content

nshathish/flask-lab2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Setup instructions for deploying a Flask app in Digital Ocean Droplet

  1. log into droplet (it is assumed you have created your droplet with ssh enabled)

    ssh root@<your_droplet_public_ip>
  2. install apache

    sudo apt-get update
    sudo apt-get install apache2
  3. install and enable mod_wsgi

    sudo apt-get install libapache2-mog-wsgi python-dev
    sudo a2enmod wsgi
  4. create the flask app

    cd /var/www
    git clone https://github.com/nshathish/flask-lab2.git
    cd flask-lab2
  5. setup virtual environment and install flask

    sudo apt-get install python-pip
    sudo pip install virtualenv
    sudo virtualenv venv
    source venv/bin/activate
    sudo pip install Flask

    try running the app

    sudo python app.py

    if app is running ok, deactivate environgment

    deactivate
  6. serving flask app with wsgi

    inside /var/www/flask-lab2

    nano flask_lab2.wsgi

    in flask_lab2.wsgi write the following

    import sys
    import logging
    logging.basicConfig(stream=sys.stderr)
    sys.path.insert(0, "/var/www/flask-lab2")
    from app import app as application
  7. configure and enable virtual host

    sudo nano /etc/apache2/sites-available/flask-lab2.conf

    write the following in the flask-lab2.conf

    <VirtualHost *:80>
      ServerName flask-lab2.myserver.com
      ServerAdmin root@nshathish.com1
      WSGIScriptAlias / /var/www/flask-lab2/flask-lab2.wsgi
      WSGIDaemonProcess flask-lab2
      <Directory /var/www/flask-lab2>
          WSGIProcessGroup flask-lab2
          WSGIApplicationGroup %{GLBAL}
          Order deny,allow
          Allow from all
      </Directory>
      ErrorLog ${APACHE_LOG_DIR}/error.log
      LogLevel warn
      CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
  8. disable the default site and enable flask-lab2

    sudo a2dissite 000-default.conf
    sudo a2ensite flask-lab2.conf
    sudo service apache2 reload
  9. view your flask app in browser

    http://<your_public_ip>

Setup instuctions for deploying a flask application to AWS Ec2 instance running amazon-linux-2 (free tier)

sudo su
yum install python3-devel httpd httpd-devel gcc git -y
pip3 install mod_wsgi

after installing restart the machine

mod_wsgi-express start-server

if you see the server running, then mod_wsgi installation has been successful

mod_wsgi-express module-config >> /etc/httpd/conf/httpd.conf

this didn't work (gor permission denied error, even with sudo), so had to pipe that to a temp file and copy the contents manually to /etc/httpd/conf/httpd.conf

mod_wsgi-express module-config > temp.conf
cat temp.conf

this would look something like the following:

LoadModule wsgi_module "/usr/local/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"

following on,

cd /var/www
git clone https://github.com/nshathish/flask-lab2.git
cd flask-lab2/
nano flask-lab2.wsgi

copy the following contents into the above file

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/flask-lab2")
from app import app as application
sudo nano /etc/httpd/conf.d/flask-lab2.conf

copy the following contents into the above file

<VirtualHost *:80>
  ServerName flask-lab2.myserver.com
  ServerAdmin root@nshathish.com1
  WSGIScriptAlias / /var/www/flask-lab2/flask-lab2.wsgi
  WSGIDaemonProcess flask-lab2
  <Directory /var/www/flask-lab2>
      WSGIProcessGroup flask-lab2
      WSGIApplicationGroup %{GLOBAL}
      Order deny,allow
      Allow from all
  </Directory>
  ErrorLog /var/log/httpd/error.log
  LogLevel warn
  CustomLog /var/log/httpd/access.log combined
</VirtualHost>
sudo service httpd restart
curl http://localhost

if you get Hello World! then your flask application is running on apache with mod_wsgi, successfully.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages