1

I'm trying to deploy a simple hello world flask app on a linux server (Ubuntu 18.04.3). I'm logged into the linux box as bobtheuser. However, when I access the , I only see the contents "Index of/" listing the contents of /var/www/html/, i.e. the flask webapp isn't starting up.

flask app setup The app directory is setup like so:

'/var/www/html/helloflask
├── __init__.py
├── my_flask_app.py
├── my_flask_app.wsgi

my_flask_app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello world! Hello Apache2 webserver!"

if __name__ == "__main__":
    app.run()

my_flask_app.wsgi

#!/usr/bin/env python3

import logging
import sys
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/html/helloflask/')
from my_flask_app import app as application
application.secret_key = 'helloflask-sk'

/etc/apache2/sites-available/helloflask.conf

<VirtualHost *:80>
     # Add machine's IP address (use ifconfig command)
     ServerName 128.250.89.117
     # Give an alias to to start your website url with
     WSGIScriptAlias / /var/www/html/helloflask/my_flask_app.wsgi
     <Directory /var/www/html/helloflask>
     # set permissions as per apache2.conf file
            Options FollowSymLinks
            AllowOverride None
            Require all granted
     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/error.log
     LogLevel warn
     CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
AndreyIto
  • 349

1 Answers1

1

I know this might be a bit too late to answer but I would like to redirect you to the following page which contains all the steps you need to take in order to deploy your Flask application over the internet, but before that make sure that apache2 is correctly installed on the machine:

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps#setup

After completing the steps from the website above, make sure to run this:

// this will remove the default apache2 configuration

a2dissite 000-default.conf

// after you removed the default configuration, restart apache2

service apache2 restart

Hope this helps.

Kind regards.