Deploy Django to DreamCompute on Ubuntu with Apache – Part 4

Written by and posted on Jun 3, 2019

Django, Ubuntu, and Apache logos side by side.

In the previous part of this tutorial, Deploy Django to DreamCompute on Ubuntu with Apache – Part 3, we’ve successfully installed and configured our Django project to run on a virtual environment.

With everything now set up and working correctly with Django, it is time to install and configure Apache to run our site.

First, let’s deactivate our virtual environment. We can do so by running the following:

(env_name) [email protected]_name:~/$ deactivate

Next, we want to install Apache alongside a Python 3 WSGI adapter module. This module will help us run Django with Apache. Run the following command to install the packages:

[email protected]_name:~/$ sudo apt-get install apache2 libapache2-mod-wsgi-py3

You will be prompted to say Yes or No. Press Y and hit Enter to begin installing the packages.

Once installed, we’d need to configure our virtual host file, so it picks up our Django project and its static directory.

[email protected]_name:~/$ sudo nano /etc/apache2/sites-available/000-default.conf

Running the command above will allow you to edit the virtual host file. Go ahead and delete everything within the file. You can then copy the following template, make your edits, and paste it into the terminal then press Ctrl + X, Y, then Enter to save.

<VirtualHost *:80>
	ServerAdmin [email protected]

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	Alias /static /home/ubuntu/
    	<Directory /home/ubuntu/>
        	Require all granted

    	<Directory /home/ubuntu/>
            		Require all granted

    	WSGIDaemonProcess projectname python-path=/home/ubuntu/ python-home=/home/ubuntu/
    	WSGIProcessGroup projectname
    	WSGIScriptAlias / /home/ubuntu/

Replace all instances of with your domain and projectname with your project name.

The last step we would need to do is to restart Apache. We can restart Apache with the following command:

[email protected]_name:~/$ sudo systemctl restart apache2

That’s it! Now if we go to our domain, we should see our Django site fully operational.

Note: The configuration we have above only runs on port 80. Port 80 usually is how we would access a site through a non-secure HTTP connection. We’ll talk about SSL certificates and HTTPS in the next part of the tutorial.


Submit a Comment

Your email address will not be published. Required fields are marked *

About Me

Person standing with coffee mug with dog by his leg

My name is Tony, and I am an Experience Designer. I love creating games, websites, and interactive experiences. Best of all, I love to teach and provide others the tool they need to ignite their passion.

More About Me