From 17b11a14fd1ca2291955484cafd7d95e903cc212 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Thu, 16 Jul 2020 09:40:09 -0400 Subject: [PATCH] Create mod_wsgi on Ubuntu notes --- ...ng Apache2 and mod_wsgi on Ubuntu 18.04.md | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/Installing Apache2 and mod_wsgi on Ubuntu 18.04.md diff --git a/docs/Installing Apache2 and mod_wsgi on Ubuntu 18.04.md b/docs/Installing Apache2 and mod_wsgi on Ubuntu 18.04.md new file mode 100644 index 0000000..9a10f33 --- /dev/null +++ b/docs/Installing Apache2 and mod_wsgi on Ubuntu 18.04.md @@ -0,0 +1,74 @@ +# Installing Apache2 and mod_wsgi on Ubuntu 18.04 + +Prepare the system: +```bash +# Update the System +sudo apt update && sudo apt upgrade -y + +# Install Apache, mod_wsgi, and python3-venv module +sudo apt install apache2 libapache2-mod-wsgi-py3 python3-venv -y + +# Add User to www-data Group +sudo usermod -aG $(whoami) www-data +``` + +For the group assignment to take effect you need to logout and back in. + +Prepare document root: +```bash +# Make Directory Structure in Root of: +. +└── api + └── webqueue2_api + ├── __init__.py + └── webqueue2_api.wsgi + +# Create Python virtual environment +cd /var/www/html && python3 -m venv venv +``` + +**__init__.py:** (Whatever the API code is) +```python +from flask import Flask +app = Flask(__name__) +@app.route("/") +def hello(): + return "Hello, Flask!" +if __name__ == "__main__": + app.run() +``` + +**webqueue2_api.wsgi** (Code calling the Flask app) +```python +#!/usr/bin/python3 +import sys +sys.path.insert(0,"/var/www/html/api") +from webqueue2_api import app as application +``` +Configure Apache2 +```bash +# Add Apache configuration +sudo nano /etc/apache2/sites-available/flasksite.conf +``` + +**flasksite.conf** +``` +WSGIPythonHome /var/www/html/api/webqueue2_api/venv + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + WSGIScriptAlias /api /var/www/html/api/webqueue2_api/webqueue2_api.wsgi + +``` + +```bash +# Enable the new site +sudo a2ensite flasksite.conf + +# Reload apache2 +sudo systemctl reload apache2 +``` \ No newline at end of file