Websites & apps

Host a Python (Flask or Django) app in cPanel with Setup Python App

Run a Flask or Django application on cPanel hosting with Setup Python App: create a virtualenv, configure passenger_wsgi.py, install requirements and restart.

IntermediatecPanel hosting2 min read

The Setup Python App tool in cPanel (provided by CloudLinux) creates a Python virtual environment for your project and serves it through Phusion Passenger using WSGI. It is a simple way to host a Flask API, a Django site or a small dashboard next to your other websites.

Before you start

  • Your project with a requirements.txt.
  • A domain or subdomain for the app, e.g. api.example.com. See create a subdomain.
  • Terminal or SSH access to run pip and Django commands.

Create the application

  1. Open cPanel → Software → Setup Python App and click Create Application.
  2. Python version: choose the version your project uses (for example 3.11 or 3.12).
  3. Application root: e.g. apps/myapi, outside public_html.
  4. Application URL: the domain and optional path.
  5. Application startup file: passenger_wsgi.py (default).
  6. Application Entry point: application (default).
  7. Add Environment variables such as DJANGO_SETTINGS_MODULE or SECRET_KEY.
  8. Click Create.

Upload code and install requirements

  1. Upload your project into the application root (File Manager, FTP or Git).
  2. Copy the virtual environment command shown at the top of the app page, e.g. source /home/user/virtualenv/apps/myapi/3.12/bin/activate && cd /home/user/apps/myapi.
  3. Paste it in Terminal and run pip install -r requirements.txt.
  4. Alternatively, enter requirements.txt under Configuration files in the app settings and click Run Pip Install.

Connect the WSGI entry point

Edit passenger_wsgi.py so it imports your app as application.

Flask (app object app in main.py):

from main import app as application

Django (project named mysite):

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Click Restart on the app page after each change.

Django: static files and database

  • Set ALLOWED_HOSTS = ['api.example.com'] and DEBUG = False.
  • Set STATIC_ROOT to a folder inside the domain's document root, e.g. /home/user/api.example.com/static, then run python manage.py collectstatic.
  • Use a cPanel MySQL database (create one) with host localhost and the mysqlclient or PyMySQL package, then run python manage.py migrate.

Note: Passenger starts the app on demand. Long-running background workers (Celery, schedulers) are not suitable for shared hosting; use cron jobs for periodic tasks.

Troubleshooting

  • "Something went wrong" / 500: check stderr.log in the application root, or set a Passenger log file in the app settings. Missing modules mean pip ran in the wrong environment.
  • Static files missing: STATIC_ROOT is outside the document root, or collectstatic was not run.
  • Changes not visible: click Restart or touch tmp/restart.txt.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.