Deploy Django on Shared Hosting — Step-by-Step (2025)

Deploy Django on Shared Hosting — Step-by-Step (2025)

Introduction — why “shared hosting” still matters (and the reality)

If you want a low-cost place to publish a small Django site, shared hosting can still be attractive. But shared hosting was designed for PHP sites and static pages — running a full Django app takes planning, patience, and the right host features. This guide explains how to deploy Django on shared hosting safely and reliably: what’s possible, exact steps many admins use (virtualenv, Passenger/mod_wsgi), common pitfalls, and when you should move to a VPS or PaaS.

I’ll walk you through a real workflow I’ve used: prepare the project, configure WSGI/Passenger, handle static/media, secure credentials, test, and troubleshoot — plus pointers to authoritative docs. Where a host-specific step exists (cPanel’s Python App, CloudLinux/Passenger), I link to vendor docs so you can follow along. cPanel & WHM DocumentationHosting Knowledge Base


Deploy Django on Shared Hosting — Step-by-Step (2025)

Quick comparison — options on shared hosting

OptionTypical host supportProsCons
cPanel Setup Python App + PassengerCloudLinux / cPanel hostsEasy virtualenv creation, Passenger integrationNot universal, some limits on versions. Hosting Knowledge Basejvmhost.com
Passenger + custom virtualenvMany hosts with PassengerWell-supported for WSGI appsRequires SSH + careful path config. Hosting Knowledge Base
mod_wsgi (Apache)Rare on shared—needs host supportNative WSGI integrationOften not available on stock shared plans. cPanel Support
CGI / cron + static site (workaround)UniversalCheap fallback for tiny appsLimited capability — not real Django deployment.

If your host offers a “Setup Python App” or a Passenger-managed Python environment, you’re in the best position for a real Django deployment on shared hosting. If not, consider a low-cost VPS or a PaaS (PythonAnywhere, Render, Fly.io, etc.). Hosting Knowledge BaseReddit


Before you start — checklist (prepare locally first)

  • Use a clean virtualenv and requirements.txt.
  • Set DEBUG = False and add actual ALLOWED_HOSTS.
  • Move sensitive settings to environment variables (SECRET_KEY, DB credentials).
  • Make sure static and media file settings exist (STATIC_ROOT, MEDIA_ROOT).
  • Confirm you have SSH access (highly recommended).
  • Check with your host support whether Passenger or mod_wsgi is available. (If your cPanel has “Setup Python App”, follow that.) cPanel & WHM DocumentationHosting Knowledge Base

Step-by-step guide (practical workflow)

1) Prepare and test locally

  1. Freeze dependencies:
    pip freeze > requirements.txt
  2. Ensure ALLOWED_HOSTS = ['yourdomain.com'] and DEBUG = False in production settings (or read from env).
  3. Add STATIC_ROOT = BASE_DIR / 'staticfiles' and MEDIA_ROOT = BASE_DIR / 'media'.
  4. Collect static locally to verify:
    python manage.py collectstatic --noinput
  5. Test with a local WSGI server: gunicorn myproject.wsgi (optional).

This stage avoids surprises on the host.


2) Create Python App / Virtualenv on the host

If your host has a cPanel Setup Python App (CloudLinux), use it — it creates a virtualenv and gives you the activation command and a startup file template. If not, SSH into your account and create a venv manually:

python3 -m venv ~/venvs/myapp
source ~/venvs/myapp/bin/activate
pip install -r requirements.txt

Document the venv path — you’ll need it in Passenger/mod_wsgi startup files. cPanel docs explain this flow. cPanel & WHM DocumentationHosting Knowledge Base


3) Upload your project and configure WSGI entry point

Upload your project (SFTP or git + pull). Typical layout: /home/username/myapp/. Create a passenger_wsgi.py (or passenger_wsgi.py depending on host) in your app root:

import sys, os
# adjust path to your project root and venv site-packages
sys.path.insert(0, '/home/username/myapp')
sys.path.insert(0, '/home/username/myapp/myproject')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
# Optionally set PYTHONPATH to virtualenv site-packages
activate_this = '/home/username/venvs/myapp/bin/activate_this.py'
with open(activate_this) as f:
    exec(f.read(), dict(__file__=activate_this))

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Paths must match your host’s layout — small mistakes here are the most common cause of “passenger error” messages. Check host docs and forum posts for typical passenger_wsgi.py examples. Stack OverflowReddit


Deploy Django on Shared Hosting — Step-by-Step (2025)

4) Static files & media — serve them efficiently

On shared hosting, Apache/nginx typically serves static files — Django should not. Steps:

  1. Set STATIC_ROOT to a folder outside the project or inside public_html/static/ if host enforces that.
  2. Run python manage.py collectstatic on the host (inside virtualenv).
  3. Ensure filesystem permissions allow the webserver to read static files (forums note common permission issues). Django Forum

For media uploads, store files outside the code folder and serve via a protected route or a CDN if possible.


5) Database — SQLite vs MySQL/Postgres

  • SQLite is supported everywhere but not ideal for multi-user production or heavy write loads.
  • For real sites use the host’s MySQL/MariaDB (or managed DB) and configure DATABASES accordingly. Create the DB and DB user in cPanel and update settings.py with env-based credentials. Many shared hosts provide a MySQL wizard in cPanel; follow it and test connections. Hosting Knowledge BaseHostingHome | KB

6) Environment & security

  • Use environment variables or a .env file (read by python-dotenv) for secrets — never commit SECRET_KEY to git.
  • Ensure database credentials are restricted to the DB user and the web user has least privilege.
  • Turn on HTTPS (use Let’s Encrypt in cPanel) and, if supported, enforce TLS for DB connections when possible.
  • Set proper file permissions and disable directory listing. These reduce exposure on a shared machine.

7) Restart & debug using logs

After configuration, restart the app (cPanel interface or touch the WSGI file). If it fails:

  • Check Passenger/Apache error logs and your Django logs (where you configured them).
  • Common errors: wrong PYTHONPATH, wrong virtualenv activation, missing dependencies, permission errors reading static/media.
  • Use a small test view returning 200 OK to verify WSGI basics before enabling full app.

Community threads (StackOverflow / Reddit / Django forums) contain many practical error examples and fixes that match passenger_wsgi path issues. Stack OverflowReddit


When shared hosting becomes the wrong tool

Shared hosting is best for small, low-traffic sites. Consider upgrading if you need:

  • Frequent deployments, custom system packages, or background workers.
  • Guaranteed uptime/isolated performance (VPS or managed PaaS).
  • Modern orchestration (Docker/Kubernetes) or horizontal scaling.

Platforms to consider when ready: DigitalOcean App Platform, Render, Railway, PythonAnywhere, Heroku alternatives — they remove many shared-hosting constraints.


Troubleshooting quick reference

SymptomLikely causeQuick fix
Passenger error #2Incorrect passenger_wsgi or pathsRe-check sys.path and virtualenv activation. Stack Overflow
Static files 404Wrong STATIC_ROOT or permissionsRun collectstatic; fix folder ownership/permissions. Django Forum
DB connection failureWrong credentials, host, or DB not createdVerify DB, user, host (localhost vs remote), and privileges. HostingHome | KB

Deploy Django on Shared Hosting — Step-by-Step (2025)

Final security & maintenance checklist

  • Keep DEBUG=False.
  • Rotate secrets and use environment variables.
  • Back up DB and media regularly.
  • Limit file upload sizes and validate file types.
  • Monitor logs and set up an alerting email.

Conclusion — shared hosting works if you know its limits

Yes, you can run Django on shared hosting — but success depends on host features (Python app support / Passenger), SSH access, and careful configuration of virtualenv, WSGI entry point, static/media, and DB. For small projects and prototypes, shared hosting is cost-effective. For anything that needs reliability, scaling, or modern CI/CD workflows, plan a migration path to VPS/PaaS early.

If you want, I can create:

  • A passenger_wsgi.py template customized to your host layout, or
  • A step-by-step checklist (one-page) that you can print and follow during deployment.

Call to Action

Are you deploying now? Paste your passenger_wsgi.py and a short ls -la of your project folder (anonymized) in the comments — I’ll point out the most likely path issues and fixes. Want the printable checklist/template? Say “Checklist please” and I’ll generate it right away.


Key references

1 Comment

Leave a Reply

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