Skip to content

Commit

Permalink
Create mod_wsgi on Ubuntu notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Jul 16, 2020
1 parent aa9c444 commit 17b11a1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions docs/Installing Apache2 and mod_wsgi on Ubuntu 18.04.md
Original file line number Diff line number Diff line change
@@ -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
<VirtualHost *:80>
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
</VirtualHost>
```

```bash
# Enable the new site
sudo a2ensite flasksite.conf

# Reload apache2
sudo systemctl reload apache2
```

0 comments on commit 17b11a1

Please sign in to comment.