Skip to main content
Django apps run on the Python Selector via a thin passenger_wsgi.py shim. Static files are served by Apache, not Django. For the underlying tool, see Python.

Before you begin

  • A Python app created in cPanel, version 3.10 or 3.11.
  • The app root contains your Django project (manage.py, <projectname>/settings.py).
  • A requirements.txt listing Django and your other packages.

Wire up Passenger

1

Create passenger_wsgi.py in the app root

passenger_wsgi.py
import os
import sys

sys.path.insert(0, '/home/<user>/myapp')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Replace <user> and myapp with your real cPanel user and project name.
2

Install dependencies

Click Run Pip Install in the cPanel app management page. Make sure requirements.txt is listed under Configuration files.
3

Run migrations and collect static files

Over SSH:
source ~/virtualenv/myapp/3.11/bin/activate && cd ~/myapp
python manage.py migrate
python manage.py collectstatic --noinput
4

Restart

Click Restart in the cPanel UI.

Serve static files

Django doesn’t serve /static/ in production. Have Apache do it. Add to the app root’s .htaccess above the Selector-managed block:
Alias /static/ /home/<user>/myapp/staticfiles/
<Directory "/home/<user>/myapp/staticfiles">
  Require all granted
</Directory>
Set STATIC_ROOT = BASE_DIR / 'staticfiles' in settings.py so collectstatic writes there.

Common issues

DJANGO_SETTINGS_MODULE doesn’t match your project layout. Open passenger_wsgi.py and confirm the module path. Then touch tmp/restart.txt.
Common with numpy, pandas, Pillow. Install one at a time over SSH, or pre-build wheels on a dev machine.
Add your domain to ALLOWED_HOSTS in settings.py. Restart.

Need a hand?

Open a ticket

Best for anything that needs an account check or a config change on our end.

Live chat

Faster for quick questions during business hours.