Instructions
Install python wsgi apache module.
sudo apt-get install libapache2-mod-wsgi-py3 python-dev
Install flask.
pip3.6 install flask
Verify Apache is running.
apache2 -f /etc/apache2/apache2.conf -k start
Create wsgi file with same name as python applicaton.
touch my_flask_app.wsgi
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>
Enable site from file with a2ensite.
sudo a2ensite /etc/apache2/sites-available/ExampleFlask.conf
Restart Apache2.
apache2 -f /etc/apache2/apache2.conf -k stop apache2 -f /etc/apache2/apache2.conf -k start
Related articles
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
Add Comment