How to Install Django on a Hosting Server: A Step-by-Step Guide

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Whether you’re launching a small website or a full-fledged web application, deploying Django on a hosting server is a critical step. In this guide, we’ll walk through the process of installing Django on a typical Linux-based hosting server.

✅ Prerequisites

Before beginning, make sure your hosting server has the following:

  • Access via SSH

  • Python 3.6+ installed

  • pip (Python package manager)

  • Virtualenv (optional but recommended)

  • A domain or subdomain (optional)

  • Basic knowledge of Linux commands

Step 1: Connect to Your Server via SSH

ssh username@your_server_ip

Replace username and your_server_ip with your actual server credentials.

Step 2: Create a Project Directory

Navigate to the directory where you want your Django project to live:

mkdir ~/myproject
cd ~/myproject

Step 3: Set Up a Virtual Environment

Using virtualenv is a good practice to isolate your project’s dependencies.

python3 -m venv venv
source venv/bin/activate

Once activated, your terminal prompt will reflect the virtual environment.

Step 4: Install Django

With the virtual environment active, run:

pip install django

You can check the installation with:

django-admin --version

Step 5: Create a Django Project

Now you can create a new Django project:

django-admin startproject mysite .

The dot at the end ensures the files are placed in the current directory.

Step 6: Run Migrations and Create Superuser

Run initial database migrations:

python manage.py migrate

Create an admin user:

python manage.py createsuperuser

Follow the prompts to set up a username and password.

Step 7: Test Django with Built-in Server

For initial testing, use Django’s built-in server:

python manage.py runserver 0.0.0.0:8000

You can now visit your server’s IP address on port 8000 in the browser:

http://your_server_ip:8000

Step 8: Prepare for Production

For production use, you’ll need:

  • Gunicorn or uWSGI as a WSGI server

  • Nginx or Apache as a reverse proxy

  • PostgreSQL or MySQL if not using SQLite

  • SSL certificate (optional but highly recommended)

Install Gunicorn:

pip install gunicorn

Run Gunicorn:

gunicorn --bind 0.0.0.0:8000 mysite.wsgi

For a production setup, configure a systemd service and a reverse proxy with Nginx to manage traffic and ensure your app runs continuously.