CloudLinux

How to set up a Python app in cPanel with CloudLinux Python Selector

Deploy a Flask or Django app on cPanel hosting with Setup Python App: choose the Python version, configure passenger_wsgi.py, install requirements and restart.

IntermediatecPanel hosting with CloudLinux2 min read

With CloudLinux's Python Selector you can run Python web apps such as Flask, Django or FastAPI (through a WSGI adapter) on cPanel hosting. Each app gets its own virtual environment and is served on your domain by Passenger.

Before you start

  • cPanel access with Setup Python App in cPanel → Software.
  • Your app's code and a requirements.txt.
  • A domain or subdomain for the app.

Create the application

  1. Go to cPanel → Software → Setup Python App.
  2. Click Create Application.
  3. Python version: choose the version your app needs, for example 3.11 or 3.12.
  4. Application root: a folder outside public_html, such as myflask.
  5. Application URL: choose the domain and optional path.
  6. Application startup file: passenger_wsgi.py.
  7. Application entry point: application.
  8. Click Create. cPanel creates the folder, a virtual environment and a sample passenger_wsgi.py.

Upload your code

Upload your project into the application root with File Manager, FTP or Git. Keep the generated passenger_wsgi.py and edit it to load your app.

Flask

from app import app as application

This assumes your Flask object is named app in app.py.

Django

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

Install requirements

  1. On the app page, enter requirements.txt in the Configuration files box, click Add, then Run Pip Install.
  2. Or copy the source …/activate command from the top of the app page, run it in cPanel → Advanced → Terminal, then run pip install -r requirements.txt.

Django extras

  • Add your domain to ALLOWED_HOSTS.
  • Run python manage.py migrate and python manage.py collectstatic inside the virtual environment.
  • Serve static files from a folder in public_html and set STATIC_ROOT to it.
  • Use a MySQL database created in cPanel (see MySQL Database Wizard) with the mysqlclient or PyMySQL driver.

Restart and test

Click Restart on the app page after every change, then open the application URL. Errors are written to stderr.log in the application root.

Troubleshooting

"We're sorry, but something went wrong"

Passenger could not load the app. Read stderr.log; usually an import error or a missing package.

ModuleNotFoundError

Packages were installed outside the virtual environment. Activate it first, then reinstall.

pip install is killed

Heavy packages can exceed memory limits during build. Install one at a time and check Resource Usage.

Note: Long-running workers (Celery, schedulers) are not suited to shared hosting. Use cron jobs for scheduled tasks, or a VPS for workers.

Similar steps for JavaScript apps are in setting up a Node.js app.

Frequently asked questions

Can I run FastAPI?

Passenger uses WSGI, while FastAPI is ASGI. Wrap it with an ASGI-to-WSGI adapter such as a2wsgi, or use Flask or Django for shared hosting.

Can I change the Python version later?

Yes, but the virtual environment is rebuilt, so run pip install again afterwards.

Where should I store secrets?

Add them as environment variables on the app page instead of committing them in code, then read them with os.environ.

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.