d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

Learn How to Deploy a Django Application

In this post, we’ll go over the steps to deploy a Django application on a production server. I am using an AWS ec2 server, an Ubuntu 20.04 instance, and Python 3.8. The steps are the same for most versions of Ubuntu and Python, however, the syntax might differ based on the version you are using.

Steps

  1. Install Apache2.
  2. List out the project’s folder and file’s path.
  3. Collect static files.
  4. Migrate the database.
  5. Change the permission and ownership of the database files and other folders.
  6. Make changes in the Apache config file.
  7. Enable the site.
  8. Install WSGI mod in Apache2.
  9. Restart the Apache Server.

Step 1: Install Apache 2

 The following are the commands to install the Apache 2 server on the Ubuntu instance.

Step 2: List Out the Project’s Folder/File Path

It is important to list the project path in order to follow the next step. List your Django project’s name and path, application name and path, environment’s location path, and WSGI file path.

Step 3: Collect Static Files

Django provides a mechanism for collecting static files into one place so that they can be served easily. 

Open Setting.py using the following command:

vi Demo/DemoProject/DemoProject/settings.py

Activate the source and collect the static files using the following commands:

Step 4: Migrate the Database

Migrate the database using the MakeMigration and Migrate command:

Step 5: Change Permission and Ownership

If you are using a SQLite database, then change the permissions of the SQLite file. Also, change the ownership of the Django project folders.

The following commands will change the permission and ownership of the files and folders.

Step 6: Changes in Apache Config File 

We need to make a few changes in the 000-default.conf file. Before that, though, make backup of the file. The following are the commands to open the file and create backup of the file.

Add the below code to the file:

After adding the above snippet, the config file will look like this:

Step 7: Enable the Site

Now enable the above conf file using the a2ensite command.

Step 8: Install WSGI mod in Apache 2

Install the WSGI mod library for the Apache 2 server using the following command. After installation, enable the WSGI.

Step 9: Restart the Apache Server

Restart the Apache server using the following command:

And you’re done!

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this