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

$ startproject arana .
$ vim arana/

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.

$ ./ makemigrations
$ ./ 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 /home/ubuntu/arana/arana>
Require all granted
WSGIDaemonProcess arana python-home=/home/ubuntu/arana/venv
WSGIProcessGroup arana
WSGIScriptAlias / /home/ubuntu/arana/arana/

Updata permissions

$ chmod 664 ~/arana/db.sqlite3
$ sudo ufw allow ‘Apache Full’
$ sudo apache2ctl configtest
$ sudo systemctl restart apache2


Thanks for Watching!

I'm Available for Hire or Freelance
Back to ArticlesGet In Touch