How to install Django on a CentOS 7 VPS or Dedicated Server

How to install Django on a CentOS 7 VPS or Dedicated Server

When building a website, similar components are required, and you do not have to reinvent the wheel every time you build a new website. Django is the tool you require for this.

In this article, various methods of installing Django are covered and how to create your first project.

Special note: consult HostAdvice’s Best Django Hosting page to find the leading web hosts in this category, including expert and user reviews.

Overview

Django is a powerful tool for writing web applications. Using Django framework is the easiest way to make an idea a business reality. It makes sure you have as fewer hassles as possible while you are creating your web applications. It has dozens of features such as user authentication and RSS feeds and is very secure. So let’s see how to install Django on a CentOS

Installation of Django

Django installation is done in several ways, and we shall cover a few of them in this article. They all rely on the EPEL repository for CentOS and RedHat like distributions. The EPEL repository contains extra packages not found in the core distribution. To use EPEL, type yum command to configure the use of EPL repository;

sudo yum install epel-release

Below are some of the methods of installing Django;

  • Installing from packages
  • Installing through pip
  • Installing through pip in a virtual environment
  • Installing the development version through git

Installing from packages

We use the yum package manager to install Django packages from the EPEL repository. The drawback is that the version contained in EPEL may not be the latest one. However, this process is straightforward, type the following:

sudo yum install python-django

To verify installation:

django-admin --version

If successful it should show:

1.6.0

Installing from pip

If you would like to install the latest Django, this method is for you. We first install the pip package manager and then install Django. So type the following;

sudo yum install python-pip

Next, you can now install Django by typing:

sudo pip install django

Now to check if the installation was successful:

django-admin --version

If successful, it should show you the following;

1.7.5

Note that the version in pip is more up to date than the one from EPEL.

Installing through pip in a virtual environment

Use the Virtualenv tool to create virtual environments. It is in these virtual environments that python packages are installed without affecting the rest of the system. It is useful if your projects tend to conflict with other different projects.

First, is to install pip from the EPEL repository.

sudo yum install python-pip

With pip installed, we can now install the Virtualenv package;

Installing through pip in a virtual environment

Now each time you start a project you have to create a virtual environment for it. So we are going to set a new project category:

mkdir ~/newproject
cd ~/newproject

Next, create a virtual environment by typing;

virtualenv newenv

Note: newenv >is just a name; you can choose whichever name you want.

The above command installs python and pip into the virtual environment. To install packages in our virtual environment, just type;

source newenv/bin/activate

Your command line should change and look like the following;

(newenv)username@hostname:~/newproject$

Now install Django using pip;

pip install django

To verify the installation, type;

django-admin --version

It should show;

1.7.5

If you wish to leave your environment type deactivate;

deactivate

To restart, type the following;

cd ~/newproject
source newenv/bin/activate

Installing the development version through git

This method installs the latest development version. It requires us to get the Django code directly from the git repository. Install git and pip on our system using the >yum command;

sudo yum install git python-pip

Clone the repo to a directory called django-dev.

git clone git://github.com/django/django ~/django-dev

The repository can now be installed using pip. We will use the –e option to install in editable mode.

sudo pip install -e ~/django-dev

We are now set to verify the installation. To do so just type,

django-admin --version

If it has installed successfully, it should show;

Conclusion

We have gone through a few ways for you to install Django on your CentOS 7 machine. Depending on your choice of installation, you can get fresh new features for the development version, or you can get the most stable version.  So each installation has its disadvantages and advantages. We certainly hope you get to enjoy the many features of Django firsthand.

 

Check out the top 3 Dedicated server hosting services:

Hostinger
NZ$4.79 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
IONOS
NZ$1.60 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
NZ$4.00 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to Setup a Docker Swarm Cluster on a CentOS 7 VPS or Dedicated Server

This how-to article will help you install and configure Docker Swarm on CentOS 7
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

Use Python to Automate Routine Tasks on Your VPS or Dedicated Server

Here we'll use basic knowledge of Python to teach you how to leverage the extrao
less than a minute
Md. Ehsanul Haque Kanan
Md. Ehsanul Haque Kanan
Hosting Expert

Install & Configure the Caddy web server on a CentOS 7 VPS

Caddy is the only new server's that secure by default. It's growing in popularit
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How to Connect to a Server by Using SSH on Linux and Mac

Most servers in the world are run on Linux servers. They’re dependable, afford
less than a minute
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top