How to run a Python app in cPanel (Flask, Django)

  1. Open "Setup Python App" (group "Software").
  2. Click "CREATE APPLICATION".
  3. "Python version" - the newest available.
  4. "Application root" - the code folder, for example pyapp.
  5. "Application URL" - domain and path.
  6. "Application startup file" - passenger_wsgi.py, "Application Entry point" - application.
  7. Click "CREATE".
New Python application
New Python application

The panel creates the folder, a virtual environment and a test passenger_wsgi.py. Upload your code and requirements.txt. Then open the app in the list, add requirements.txt in the configuration files block and run the pip install.

passenger_wsgi.py for Flask

from app import app as application

Here app.py is the application file and app is the Flask object in it.

passenger_wsgi.py for Django

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

Click "RESTART" in the app card after changing the code.

Questions and answers
The file the web server uses to start the Python app. It must define an application object.