RHEL BasedRocky Linux

How To Install Django on Rocky Linux 9

Install Django on Rocky Linux 9

In this tutorial, we will show you how to install Django on Rocky Linux 9. For those of you who didn’t know, Django is a free and open-source web application framework written in Python. It comes with a set of tools to help one build scalable web applications. Django’s primary goals are simplicity, re-usability, rapid development, and scalability.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Django on Rocky Linux. 9.

Prerequisites

  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Django on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils

Step 2. Installing Pip and Virtual Environment.

Now run the command below to install Python 3 and pip 3 on the Rocky Linux system:

sudo dnf install python3 python3-pip python3-virtualenv

To verify Python 3 version run this command:

python3 --version

Step 3. Installing Django Database.

By default, Django is not available on Rocky Linux 9 base repository. Now use pip to install Django to your system:

sudo pip3 install Django

When your installation is completed, verify it by running the following command:

django-admin --version

Step 4. Create Django Sample Project.

First, create a directory for your Django project with the command below:

sudo mkdir project
cd project

Next, use the Django admin tool to build your first project, here we named it idroot_project:

django-admin startproject idroot_project

Change the directory to the one made for the project:

cd idroot_project

We need to migrate the pending changes as shown below:

sudo python3 manage.py migrate

Now create an administrative user for the project using the following command:

sudo python3 manage.py createsuperuser

Output:

Username (leave blank to use 'root'): admin
Email address: admin@idroot.us
Password:
Password (again):
Superuser created successfully.

Step 5. Configure Firewall Rules and SELinux.

Django listens on port 8000 by default, now allow it through the firewall as shown:

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

Once done, now we configure SELinux:

sudo setsebool httpd_can_network_connect on -P

Next, we need to modify the settings.py file inside our project folder to allow Django to be accessed by external users:

nano idroot_project/settings.py

add [‘*’] in the ALLOWED_HOSTS field:

...
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['your-IP-address']
# Application definition
...

Save and close the file then, start your Django app on Rocky Linux 9 by running the following command:

sudo python3 manage.py runserver 0.0.0.0:8000

Output:

Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Sep 22, 2022 - 22:55:46
Django version 3.3.12, using settings 'idroot_project.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

Step 6. Accessing Django Web Interface.

Once successfully installed, you can access the Django application by visiting the URL http://your-server-ip-address:8000. You will see the following page:

Install Django on Rocky Linux 9

You can also access Django’s admin interface using the URL http://your-server-ip-address:8000/admin. You will see the following page:

Install Django on Rocky Linux 9

Congratulations! You have successfully installed Django. Thanks for using this tutorial for installing Django on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Django website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button