Django is a powerful web framework that can help you get your Python application or website off the ground quickly. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server is required.
Install Packages from the Ubuntu Repositories
$ sudo apt-get update
$ sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
Configure a Python Virtual Environment
$ mkdir ~/arana
$ cd ~/arana
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install django
Create and Configure a New Django Project
$ django-admin.py startproject arana .
$ vim arana/settings.py
Change this line:
. . .
ALLOWED_HOSTS = [” server_domain_or_IP “]
. . .
Add at the bottom:
. . .
STATIC_URL = ‘/static/’
STATIC_ROOT = os.path.join(BASE_DIR, ‘static/’)
Save and close.
$ ./manage.py makemigrations
$ ./manage.py collectstatic
$ deactivate
Configure Apache
$ sudo vim /etc/apache2/sites-available/arana.conf
<VirtualHost *:80>
. . .
Alias /static /home/ubuntu/arana/static
<Directory /home/ubuntu/arana/static>
Require all granted
</Directory>
<Directory /home/ubuntu/arana/arana>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess arana python-home=/home/ubuntu/arana/venv
WSGIProcessGroup arana
WSGIScriptAlias / /home/ubuntu/arana/arana/wsgi.py
</VirtualHost>
Updata permissions
$ chmod 664 ~/arana/db.sqlite3
$ sudo ufw allow ‘Apache Full’
$ sudo apache2ctl configtest
$ sudo systemctl restart apache2
Done.


