How to Install Django on CentOS 7

r00t September 8, 2017

Install Django on CentOS 7

In this tutorial we’ll learn how to install Django on CentOS 7. We will also install and configure its prerequisites. Django is a popular Web framework for writing web applications. With Django you can build faster and scalable applications, without writing the code from scratch (without reinventing the wheel). Web framework was designed to aid programmes to create applications. These web frameworks are the core and takes care of functionalities like user session management, database connectivity etc.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Django on CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Installing pip and necessary dependencies.

First thing to do is to add the EPEL repository in our system, as pip package is available in this repository. Use the commands below to install the latest version of pip:

yum install epel-release
yum install python-devel python-setuptools python-pip
sudo pip install --upgrade pip

Step 3. Installing virtualenv.

Before installing Django. You will also need to create the Python virtual environment. So you will need to install virtualenv first:

pip install virtualenv

Once virtualenv is installed, create a Python virtual environment with the following commands:

cd ~
virtualenv djangoenv

The command above will create the directory ~/djangoenv that contains your virtual environment.

Step 4. Installing Django.

First, activate the virtual environment:

source ~/djangoenv/bin/activate

Install Django globally using the following command:

pip install django

Step 5. Create your first Django project.

Now that the Django framework has been installed, you can to give it a test drive by creating a sample project:

cd ~
django-admin startproject bmw1

The command above will create a directory bmw1 in your working directory ~, and store all necessary files within.

Run the commands below in sequence to get your application started:

cd bmw1/
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 0.0.0.0:8000

Step 6. Configure Firewall.

You will need to allow port 8000 to access the Joomla from outside network. You can do this by running the following commands:

sudo firewall-cmd --zone=public --permanent --add-port=8000/tcp
sudo firewall-cmd --reload

Step 7. Accessing Django Web Installation.

Now you can access the Django web install wizard in your browser by entering the domain name port 8000 or http://your_ip/8000 to continue your Django installation.

Install Django on CentOS 7

You can also access the Django admin page by typing the URL server_IP_addr:8080/admin on your web browser:

Install Django on CentOS 7

Congratulation’s! You have successfully install and configured Django on your CentOS 7 server. Thanks for using this tutorial for installing Django on CentOS 7 system.

The Tags:

Leave a Comment

Comments are closed.