Getting Started

How to Deploy a Django Project on cPanel Shared Hosting

Updated December 2026 3 views 14 min read
Getting Started | Updated December 2026

This guide takes you all the way through deploying a production Django project on Ultra Web Hosting shared hosting. You create a Python app in cPanel, pull in your code over SSH, install your dependencies into the virtualenv, and wire Django's WSGI entry point into Phusion Passenger. It then goes deeper on the parts that trip people up in production: locking down settings.py with DEBUG off and ALLOWED_HOSTS, connecting a MySQL database with mysqlclient, running migrations and collecting static files, and reading the Passenger log when something breaks. If you only need the broad strokes for Flask or Django, start with the general Python app guide and come back here for the Django specifics.

Do Not Skip This

This Is the Deep Dive, Not the Intro

This article assumes you already have a working Django project with a requirements.txt and that you understand the Passenger model. If the words "WSGI callable" or "touch the restart file" are new, read the general guide first, then come back here for the Django production details.

01. Before You Start

Ultra Web Hosting gives you everything Django needs on a standard shared plan. Phusion Passenger is already built into the web stack, cPanel's Setup Python App (powered by the CloudLinux Python Selector) handles the virtualenv, and you get SSH access, Git, MySQL databases, a free SSL certificate, and a free CloudFlare CDN. Storage is on NVMe SSD, and our support team answers in about 12 minutes on average. For an overview of the plans built around this workflow, see the Django hosting page.

Before you begin, make sure you have the following in hand:

  • A working Django project. It should run locally and have a top level project package (the folder that contains settings.py, urls.py, and wsgi.py).
  • A requirements.txt. Generate it from a known-good local environment with pip freeze > requirements.txt so the server installs the exact versions you tested.
  • Your cPanel login and SSH access. If SSH is not enabled on your account yet, our support team can turn it on.
  • Django 4.x or 5.x on Python 3.10 or newer. Both modern Django lines run cleanly on the Python versions the selector offers.
Tip: Test the Project Locally First

Deploying is far smoother when the project already runs on your machine with python manage.py runserver. Fix import errors, missing packages, and migration problems locally where the feedback loop is fast, then push a clean project to the server.

02. Create the Python App in cPanel

This step builds the virtualenv and registers your app with Passenger. It is the same Setup Python App tool used for any Python project, so if you have followed the general guide this will look familiar.

  1. Log in to cPanel and open Setup Python App (under the Software section). Some themes label it Application Manager.
  2. Click Create Application.
  3. Python version: choose the version your project targets. The selector offers 3.8 through 3.13. For Django 4.x or 5.x, pick 3.10 or newer (for example 3.12).
  4. Application root: the folder your project lives in, relative to your home directory, for example myproject. cPanel creates this folder and puts the virtualenv alongside it.
  5. Application URL: the domain or subdomain where Django is served, for example yourdomain.com.
  6. Leave Application startup file and Entry point at their defaults (passenger_wsgi.py and application). You will create that file in Section 07.
  7. Click Create.

cPanel builds the virtual environment and shows a command near the top of the app's page that looks like source /home/youruser/virtualenv/myproject/3.12/bin/activate && cd /home/youruser/myproject. Copy that line exactly. You will use it in Section 04.

Note

cPanel drops a starter passenger_wsgi.py and a public folder into the app root when it creates the app. The public folder is the document root Passenger serves static files from, and you will use it for collected static files in Section 08.

03. Upload or Clone Your Project over SSH

Your Django project files go inside the application root cPanel just created. The cleanest way to get them there is a Git clone over SSH, but File Manager works too for a quick upload.

Option A: Clone with Git (recommended)

Git is available on the server. Connect over SSH, change into the app root, and clone your repository into it. The goal is for manage.py and your project package to sit directly in the app root.

cd ~/myproject
git clone https://github.com/youruser/yourrepo.git .

The trailing . clones into the current folder rather than a nested subfolder, so you end up with ~/myproject/manage.py and ~/myproject/myproject/settings.py rather than an extra yourrepo layer. If the folder is not empty because cPanel added its starter files, clone into a temporary folder and move the contents in, or remove the starter passenger_wsgi.py first (you replace it in Section 07 anyway).

Option B: Upload with File Manager

If you do not use Git, zip your project locally, open File Manager in cPanel, browse into the application root, upload the archive, and extract it there. Confirm that manage.py lands directly in the app root and not inside a nested folder.

Do Not Upload the Local Virtualenv

Never copy your local venv or .venv folder to the server. The server builds its own virtualenv in Section 04, and a local one carries machine-specific paths and binaries that will not work here. Add it to .gitignore and exclude it from any upload.

04. Activate the Virtualenv and Install Dependencies

You install dependencies into the virtualenv cPanel built, from the command line. Use the exact activation command cPanel showed you on the app page, because it both activates the right environment and changes into the app root.

  1. Connect to your account over SSH.
  2. Paste the activation command from the app page:
    source /home/youruser/virtualenv/myproject/3.12/bin/activate && cd /home/youruser/myproject
  3. Your prompt now shows the environment name in parentheses. Confirm the interpreter:
    which python
    python --version
  4. Install everything from your pinned requirements file:
    pip install -r requirements.txt

A typical Django requirements.txt for MySQL looks like this:

Django==5.1.4
mysqlclient==2.2.6
Tip: mysqlclient Is the Database Driver

Django talks to MySQL and MariaDB through the mysqlclient package, so add it to requirements.txt. Install it with pip inside the activated virtualenv as shown above and it builds against the system MySQL client libraries that are already present. Use MySQL in production. SQLite is fine for local development, but it is not a good fit for a live multi-process site. If the mysqlclient install ever fails to build, Section 10 covers what to check.

05. Configure settings.py for Production

The default Django settings are tuned for local development, not a public server. Before the site goes live, change four things in your project's settings.py.

Turn off debug and set allowed hosts

DEBUG = False

ALLOWED_HOSTS = ["yourdomain.com", "www.yourdomain.com"]
Never Ship With DEBUG = True

Leaving DEBUG = True on a live site exposes stack traces, your settings, and environment details to anyone who triggers an error. Set it to False before the app is public. With debug off, Django also enforces ALLOWED_HOSTS, so any domain not listed there is rejected with a DisallowedHost error.

Load the secret key from an environment variable

Do not commit SECRET_KEY to your repository. Set it as an environment variable in the Setup Python App page (open your app, use the Environment variables section, add SECRET_KEY with its value, and save), then read it in settings:

import os

SECRET_KEY = os.environ["SECRET_KEY"]

Trust your domain for CSRF

Modern Django checks the origin of form submissions against CSRF_TRUSTED_ORIGINS. List your site with the scheme included, or valid logins and form posts fail a CSRF check:

CSRF_TRUSTED_ORIGINS = ["https://yourdomain.com", "https://www.yourdomain.com"]
Tip: Keep Secrets Out of Git

Store SECRET_KEY, database passwords, and any API keys as environment variables in the cPanel app config, never in files you commit. Add any local .env to .gitignore. A leaked repository then leaks no credentials, and each environment can hold its own values with no code change.

06. Connect a MySQL Database

Create the database and a user in cPanel, grant the user access, then point Django at it. This is the production database. Keep SQLite for local development only.

  1. In cPanel, open MySQL Databases.
  2. Under Create New Database, name your database and create it. cPanel prefixes it with your account name, so the full name looks like youruser_django.
  3. Under MySQL Users, create a user with a strong password. It is also prefixed, for example youruser_djuser.
  4. Under Add User To Database, add the new user to the new database and grant it All Privileges.

Now add the database config to settings.py, reading the password from the environment (set DB_PASSWORD in the Setup Python App environment variables, as in Section 05):

import os

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "youruser_django",
        "USER": "youruser_djuser",
        "PASSWORD": os.environ["DB_PASSWORD"],
        "HOST": "localhost",
        "PORT": "3306",
    }
}

With the virtualenv active and inside the app root, create the schema and your admin account:

python manage.py migrate
python manage.py createsuperuser

The migrate command builds every table your project and Django's own apps need. The createsuperuser command walks you through making the first login for the Django admin at /admin/.

Note

Use localhost as the database host. Your database, your user, and the web app all live on the same server, so Django connects over the local socket. There is no separate database host to configure on a standard shared plan.

07. Wire passenger_wsgi.py

Passenger looks for a file named passenger_wsgi.py in your app root with a WSGI callable named application. Django already ships a WSGI application in yourproject/wsgi.py, so your job is simply to expose it under the name Passenger expects. Assume your project package is named myproject.

Replace the starter passenger_wsgi.py cPanel created with this:

import os
import sys

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

from myproject.wsgi import application

That adds the app root to the import path, tells Django which settings module to load, and imports the application object Django already defined in myproject/wsgi.py. There is nothing to run and no port to bind. Passenger imports this module and calls application for every request.

The Name Must Be application

Passenger will not start your app if the callable is named anything other than application, unless you changed the Entry point field in cPanel to match. Make sure the import line ends in as application if you rename it, or import Django's application directly as shown above.

08. Static and Media Files

In production Django does not serve its own static or media files. You collect the static files into one folder that the web server can reach, and Apache serves them as plain files. The public folder in your app root is the document root Passenger serves, so point static and media inside it.

In settings.py:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "public", "static")

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "public", "media")

Then, over SSH with the virtualenv active, gather every app's static assets into STATIC_ROOT:

python manage.py collectstatic --noinput

Anything under the public folder is served directly as a static file, so your collected CSS, JavaScript, and images at public/static/ are reachable at /static/ without Django touching the request. User uploads go to public/media/ and are reachable at /media/. Run collectstatic again any time you change static assets, then restart the app.

Tip: Static 404 Means collectstatic or a Wrong Path

If your styles or scripts return 404 after deploy, the usual cause is that you have not run collectstatic, or that STATIC_ROOT does not point inside the public folder. Fix the path, run collectstatic --noinput, and restart the app.

09. Restart and Go Live

Passenger loads your app into memory once and keeps it there, so none of your changes to code, settings, environment variables, or dependencies take effect until you restart. There are two ways to do it.

Touch the restart file

Passenger watches for tmp/restart.txt in your app root. Updating its timestamp triggers a graceful reload on the next request:

mkdir -p tmp
touch tmp/restart.txt

Click Restart in cPanel

On the Setup Python App page, each application has a Restart button. Clicking it reloads the app, with the same effect as touching the restart file.

Once you have restarted, visit your Application URL in a browser. You should see your Django site. Then visit /admin/ and log in with the superuser you created in Section 06 to confirm the database connection and static files for the admin are working.

No Restart, No Change

If you deploy new code or edit settings and the site still behaves the old way, you almost certainly forgot to restart. When in doubt after any change at all, restart the app, then reload the page.

10. Troubleshooting Common Django Deploy Errors

When Django fails, Passenger writes the Python traceback to the app's stderr log. That log is where the real cause lives behind any generic error page. Its location is shown on the Setup Python App page, and it is usually under the app root or your home directory as stderr.log. Watch it live over SSH while you reproduce the problem:

tail -f /home/youruser/myproject/stderr.log

The errors below cover almost every first-deploy Django ticket:

  • DisallowedHost at /. The domain you visited is not in ALLOWED_HOSTS. Add it (both the bare domain and the www form), then restart. See Section 05.
  • 500 error with a generic page and DEBUG off. Django raised an exception but is hiding the detail on purpose. Read the traceback in the stderr log, which names the file and line. Do not turn DEBUG back on to debug a live site.
  • Static files return 404. You have not run collectstatic, or STATIC_ROOT does not point inside the public folder Passenger serves. Fix the path, run collectstatic --noinput, and restart. See Section 08.
  • CSRF verification failed. Request aborted. Your domain is missing from CSRF_TRUSTED_ORIGINS, or you listed it without the https:// scheme. Add the full origins and restart. See Section 05.
  • mysqlclient fails to build or install. Confirm the virtualenv is active and that you are on a supported Python version, then retry pip install mysqlclient. If the build still fails, open a ticket and our support team can confirm the MySQL client libraries and development headers are in place for your account.
  • ModuleNotFoundError on a package you installed. You installed into a different environment, or the app is running an older copy. Re-activate the correct virtualenv (Section 04), reinstall, then restart.
  • Changes not taking effect. You did not restart. See Section 09.
Tip: Read the Log Before You Guess

Almost every Django deploy error is spelled out in the stderr log with a full traceback. Open the log first, reproduce the error in the browser, and read the last traceback. It is faster than changing settings at random, and our support team will ask for that same output if you open a ticket.

11. When to Move to a VPS

Passenger on shared hosting is an excellent home for most Django sites: content sites, dashboards, member areas, APIs, and internal tools with normal request-and-response traffic. There are workloads the shared model is not built for, and recognizing them early saves frustration.

Consider a VPS or dedicated server when your project needs any of the following:

  • Background workers. Task queues and job runners that must stay alive independent of web requests do not fit here. Passenger only runs your app while it is serving traffic, so there is nowhere to keep a persistent worker process running.
  • Scheduled long-running tasks. A short management command on a cron schedule is fine, but a job that needs to run for many minutes or hold resources for a long time belongs on a server you control.
  • WebSockets or ASGI. Real-time features that hold a connection open per client, and async ASGI deployments, are not supported on the shared Apache and Passenger stack. These need a VPS where you run your own async server.
  • High or spiky traffic. Shared plans cap per-account memory and processes. A site with sustained heavy load or large in-memory needs will hit those ceilings, where a VPS lets you size the box to the load.

None of this means you have to leave. Plenty of production Django sites run happily on our shared plans. When your roadmap does include real-time features, heavy background processing, or full control, a VPS gives you your own async server, scheduler, and root access. We can help you size and migrate when you get there. Managed migration is free.

Stuck Getting Django Online?

If Passenger is throwing an error you cannot decode, or you are weighing whether your project has outgrown shared hosting, open a ticket. Send us your app root, the Python version, and the stderr log output, and we will point you at the fix or the right plan.

Open a Support Ticket

Quick Recap: Django on Passenger in Seven Steps

If you only remember seven things from this guide, remember these:

  1. Create the app in cPanel with Setup Python App: choose a Python version (3.10 or newer for Django 4.x and 5.x), app root, and URL.
  2. Clone or upload your project into the app root so manage.py sits directly in it, and never copy a local virtualenv.
  3. Activate the virtualenv over SSH using cPanel's command, then pip install -r requirements.txt including mysqlclient.
  4. Harden settings.py: DEBUG = False, ALLOWED_HOSTS, SECRET_KEY from the environment, and CSRF_TRUSTED_ORIGINS.
  5. Connect MySQL: create the database and user in cPanel, add the DATABASES config, then run migrate and createsuperuser.
  6. Wire passenger_wsgi.py to import Django's application, and point static and media into the public folder after collectstatic.
  7. Restart after every change with touch tmp/restart.txt or the Restart button, and read errors from the stderr log.

Last updated December 2026 · Browse all Getting Started articles

Share: X in Reddit f Email
  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

How to Export and Back Up Your Weebly Site

Getting Started | Updated July 2026 Weebly is winding down in 67 countries, with published...

Getting Started with NodeJS

Getting Started | Updated March 2026 Node.js is a JavaScript runtime that lets you run...

Using Linux to SSH and SCP Files Over to Your Hosting Account

Getting Started | Updated August 2026 SSH and SCP are the most direct ways to manage your...

Building a Website with Publii Static CMS

Getting Started | Updated April 2026 Publii is a free, open-source static site generator with...

Do I have to have a domain name?

Getting Started | Updated November 2026 No, you do not need to already own a domain name to...



Save 30% on web hosting - Use coupon code Hosting30