Skip to content
Deploying apps4 min read

Deploy a Django project on cPanel with Setup Python App

Short answer

Create an app in cPanel's Setup Python App, upload your project to the app root, point passenger_wsgi.py at Django's WSGI application, install requirements inside the app's virtualenv, run migrate and collectstatic, then restart the app. On ArabyHost this runs on the AI/Developer plans, which include Setup Python App and SSH.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Prerequisites
  2. Step-by-step deployment
  3. Troubleshooting
  4. On ArabyHost

On cPanel, Django doesn’t run behind Gunicorn and Nginx the way most tutorials show. The Setup Python App page (CloudLinux Python Selector) creates a virtualenv and hands requests to your project through Phusion Passenger, which loads a WSGI file called passenger_wsgi.py. Get that file and a few production settings right and the rest is standard Django.

Prerequisites

  • A plan with Setup Python App and SSH. On ArabyHost that means the AI/Developer plans.
  • A domain or subdomain already pointing to the hosting account.
  • A project with a requirements.txt (pip freeze > requirements.txt locally).
  • A matching Python version: Django 5.2 needs Python 3.10 or newer, while Django 4.2 LTS also runs on 3.9.
  • A MySQL/MariaDB database if you won’t use SQLite. See creating a MySQL database.

Step-by-step deployment

1. Create the application

In cPanel open Software › Setup Python App and click Create Application:

Field Value
Python version 3.12 (or the version you develop with)
Application root mysite (a folder in your home directory, outside public_html)
Application URL your domain, e.g. example.com
Application startup file passenger_wsgi.py
Application Entry point application
Passenger log file /home/USER/logs/mysite.log

Click Create. The page then shows a command for entering the app’s virtualenv. Copy it; you will use it in every SSH session:

source /home/USER/virtualenv/mysite/3.12/bin/activate && cd /home/USER/mysite

Replace USER with your cPanel username everywhere in this guide.

2. Upload the project

Clone it over SSH or upload a ZIP with File Manager and extract it into the app root. Don’t upload your local venv folder or __pycache__. The layout should look like this:

/home/USER/mysite/
├── passenger_wsgi.py
├── manage.py
├── requirements.txt
├── .env
└── mysite/
    ├── settings.py
    └── wsgi.py

3. Install the requirements

source /home/USER/virtualenv/mysite/3.12/bin/activate && cd /home/USER/mysite
pip install --upgrade pip
pip install -r requirements.txt
pip install python-dotenv mysqlclient

If mysqlclient fails to compile, use the pure-Python PyMySQL driver instead. Run pip install pymysql and add this to mysite/__init__.py:

import pymysql

pymysql.version_info = (2, 2, 1, "final", 0)  # Django 5.1+ checks the mysqlclient version
pymysql.install_as_MySQLdb()

4. Write passenger_wsgi.py

Replace the placeholder file that cPanel created:

import os
import sys

sys.path.insert(0, os.path.dirname(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

The variable name must match the Application Entry point field (application).

5. Production settings

Keep secrets in .env in the app root (chmod 600 .env) so they work both for Passenger and for manage.py over SSH:

DJANGO_SECRET_KEY=change-me-to-a-long-random-string
DB_NAME=USER_mysite
DB_USER=USER_mysite
DB_PASSWORD=your-database-password

Then in settings.py:

import os
from pathlib import Path
from dotenv import load_dotenv

BASE_DIR = Path(__file__).resolve().parent.parent
load_dotenv(BASE_DIR / ".env")

SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
DEBUG = False
ALLOWED_HOSTS = ["example.com", "www.example.com"]
CSRF_TRUSTED_ORIGINS = ["https://example.com", "https://www.example.com"]

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": os.environ["DB_NAME"],
        "USER": os.environ["DB_USER"],
        "PASSWORD": os.environ["DB_PASSWORD"],
        "HOST": "localhost",
        "OPTIONS": {"charset": "utf8mb4"},
    }
}

STATIC_URL = "/static/"
STATIC_ROOT = "/home/USER/public_html/static"
MEDIA_URL = "/media/"
MEDIA_ROOT = "/home/USER/public_html/media"

STATIC_ROOT must sit inside the document root of the Application URL. For a subdomain that is usually a folder such as /home/USER/api.example.com, not public_html.

6. Migrate and collect static files

python manage.py migrate
python manage.py collectstatic --noinput
python manage.py createsuperuser

7. Restart and test

Click Restart in Setup Python App, or from SSH:

mkdir -p /home/USER/mysite/tmp && touch /home/USER/mysite/tmp/restart.txt

Open https://example.com/admin/. Restart again after every code or settings change.

Troubleshooting

  • Bad Request (400): the domain is missing from ALLOWED_HOSTS. Add both the bare domain and www.
  • CSRF verification failed when logging into the admin: add the https:// origins to CSRF_TRUSTED_ORIGINS.
  • The admin has no styling and static files return 404: STATIC_ROOT is outside the document root, or you forgot collectstatic. As a fallback, install WhiteNoise and add whitenoise.middleware.WhiteNoiseMiddleware right after SecurityMiddleware.
  • A generic Passenger error page: read the Passenger log file you set in step 1. It usually shows an ImportError from a wrong DJANGO_SETTINGS_MODULE, or a package installed outside the virtualenv. See Passenger app error.
  • Arabic text fails to save (Incorrect string value): the database or table isn’t utf8mb4. See MySQL error 1366.
  • Code changes don’t show up: Passenger keeps the old processes until you restart the app.

On ArabyHost

Django runs on the AI/Developer plans: Setup Python App with Python 3.9-3.12 through the CloudLinux selector (Phusion Passenger), SSH jailed in CageFS, and Git for pulling your code. The web server is LiteSpeed, SSL is issued automatically once the domain points to us, and JetBackup takes daily backups. For background tasks such as sending emails or processing queues, run a small worker process kept alive by cron. Be aware of the limits: no root access and no Docker, and your app shares the server within your account’s own resource limits. If something breaks, the Araby AI assistant in the panel can read the error logs and explain the fix. Read more in Django hosting.

FAQ

Can I run Django on a regular shared hosting plan?

Not on ArabyHost's shared, WordPress or email plans: they run PHP and have no SSH. Django needs Setup Python App and a shell for pip and manage.py, which come with the AI/Developer plans.

Do I need Gunicorn or Nginx for Django on cPanel?

No. Passenger starts and manages the Django processes from passenger_wsgi.py, and the web server serves the files that collectstatic copies into the document root. You don't install or configure Gunicorn yourself.

Should I use SQLite or MySQL for Django in production?

SQLite is fine for a small site with few writes. If several users write at the same time, or the data matters to your business, use MySQL/MariaDB with the utf8mb4 charset.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.