How Do You Install Django on a CentOS/RHEL/Fedora server?

Problem scenario
You want to install Django and have it working for browsing from a desktop workstation. You do not want to leverage Django's API functionality. How do you install and configure Django from scratch?

pip3 is probably installed. If you are not sure, you could run this: sudo find / -name pip3

You must have pip or pip3 installed. If you need assistance, see this posting.


  1. Run these two commands:
sudo yum -y install python3 mod_wsgi httpd
sudo python3 -m pip install Django
  1. Find where the core subdirectory of Django is with this command:
    sudo find / -name core -type d | grep django
  2. The parent directory, of the "core" directory found above, should have permissions configured such that the user who will start and stop Django services has the ability to write to it. Here is an example (but your path and method may vary):

sudo chown -R ec2-user:ec2-user /usr/local/lib/python3.6/site-packages/django/

  1. Run this command but change "contint" to the name your project:

django-admin startproject contint

  1. Find the external IP address of the server with this command: curl
  2. Back up the file that was created from the django-admin command. Find it (e.g., with sudo find / -name | grep contint). After it is backed up, change the original.
  3. Edit the file (with the details in the step below). Here is an example of how to edit it:
    vi /usr/local/lib/python3.6/site-packages/django/mysite/mysite/
  4. Find the ALLOWED_HOSTS stanza. Change it to look like this but replace "x.x.x.x" with the external IP address of the server:

ALLOWED_HOSTS = ['x.x.x.x']

Add or keep the single quotes inside the brackets. Save the changes and exit the file.

  1. Start the Django server (you may or many not need to change the path to the file):

python3 /usr/local/lib/python3.6/site-packages/django/contint/ runserver

  1. Draft this URL, but replace x.x.x.x with the external IP address of the server: http://x.x.x.x:4466
  2. Open a web browser and go to the URL.

Leave a comment

Your email address will not be published. Required fields are marked *