Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current Restore this Version View Page History

« Previous Version 2 Current »

Instructions

  1. Install python wsgi apache module.

    sudo apt-get install libapache2-mod-wsgi-py3 python-dev
  2. Install flask.

    pip3.6 install flask
  3. Verify Apache is running.

    apache2 -f /etc/apache2/apache2.conf -k start
  4. Create wsgi file with same name as python applicaton.

    touch my_flask_app.wsgi
  5. Create Apache config file for flask application.

    <VirtualHost *:80>
         # Add machine's IP address (use ifconfig command)
         ServerName 192.168.1.103
         # Give an alias to to start your website url with
         WSGIScriptAlias /testFlask /home/username/ExampleFlask/my_flask_app.wsgi
         <Directory /home/username/ExampleFlask/ExampleFlask/>
         		# 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>
  6. Enable site from file with a2ensite.

    sudo a2ensite /etc/apache2/sites-available/ExampleFlask.conf
  7. Restart Apache2.

    apache2 -f /etc/apache2/apache2.conf -k stop
    apache2 -f /etc/apache2/apache2.conf -k start

Reference:

  • https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/

  • https://github.com/GrahamDumpleton/mod_wsgi

  • https://www.codementor.io/@abhishake/minimal-apache-configuration-for-deploying-a-flask-app-ubuntu-18-04-phu50a7ft

  • https://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html

  • https://stackoverflow.com/questions/22711087/flask-importerror-no-module-named-app

  • https://stackoverflow.com/questions/31252791/flask-importerror-no-module-named-flask

  • https://stackoverflow.com/questions/338768/python-error-importerror-no-module-named