AWS

How to Deploy Django Project on AWS EC2

AWS provides the platform to python developers working on Django projects to deploy their projects. You can develop and deploy these projects on the same platform. It is also an easy and efficient process to deploy your Django project on AWS. This post will discuss the process of how you can deploy a Django project on AWS using an Elastic Compute Cloud (EC2) instance.

Let’s start with deploying the Django project on AWS EC2:

Deploy Django Project on AWS EC2

To deploy the Django Project on AWS EC2, simply click on the “Launch Instances” button on the EC2 page:

Simply type the name of your instance and select the amazon image machine:

Then scroll down the page to select the instance type and create a key pair file. After these settings, simply click on the “Launch Instance” button:

Once the instance is created, select the instance and click on the “Connect” button:

Select the SSH client and copy the command from the page:

Paste the command on the command prompt and replace the name of the key pair with the path of the key pair on your computer:

After the connection is made, the next step is to update the apt list of the running Ubuntu OS. For that, use the following command in the terminal:

sudo apt update

Running the above command will give the following output on the terminal:

Next step is to install the upgrades on the EC2 instance using the following command:

sudo apt upgrade

This command will get the apt packages upgrades:

To deploy the project on the server, Install the “Nginx” server using the following command:

sudo apt install nginx curl

This command will install the Nginx server to deploy the Django project:

Install python-pip to use python code in the Django project using the following command:

sudo apt install python3-pip

This command will install the python in your virtual machine:

Install a virtual environment inside python to deploy the Django project:

sudo -H pip3 install virtualenv

This command will install the virtual environment:

Create the virtual environment to deploy the project inside that using the following command:

virtualenv env

This command has created the virtual environment for the Django project:

Simply clone the git repository using the link of the code:

Create a new folder and head inside the folder using the following commands:

mkdir project

cd project

Clone the git repository inside the folder by using the following command:

git clone https://github.com/Talha331498/Django.git

This command will fetch the Django project by cloning the git:

Inside the Django project simply use the following command to run the project on the server:

python manage.py runserver

This command will load the project onto the server:

Your Django project has been deployed on the server simply use the Public IP address of the EC2 instance to visit the Django project:

The project will be displayed on the browser:

You have successfully deployed the Django project on AWS EC2 virtual machine:

Conclusion

To deploy the Django project on an AWS instance, simply create and connect to the EC2 virtual machine. Once you are connected to the virtual machine, simply install the Nginx server on which you will deploy the project. After that, install python-pip then install and create a virtual environment. Upload the project files using the git repository and head inside the project and it’s successfully deployed.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.