On cPanel hosting, Flask doesn’t run with flask run. Instead, Setup Python App (CloudLinux’s Python selector) creates a virtual environment for your app, and Phusion Passenger serves it through a passenger_wsgi.py file. Once that file exposes the right application object, the rest is installing packages and setting variables.
Before you start
- A plan with Setup Python App and SSH, such as the AI/Developer plans.
- A Flask app that runs locally, with a
requirements.txt. - A Python version from 3.9 to 3.12 that suits your packages.
- A subdomain for the app, such as
app.example.com; it’s the simplest setup.
Steps
1. Create the app in Setup Python App
In cPanel, open Setup Python App and click Create Application:
| Field | Value |
|---|---|
| Python version | For example 3.12 |
| Application root | flaskapp (path from your home folder) |
| Application URL | The domain or subdomain |
| Application startup file | passenger_wsgi.py |
| Application Entry point | application |
| Passenger log file | For example /home/USER/logs/flaskapp.log |
Click Create. The tool creates /home/USER/flaskapp, a virtual environment for it, and a placeholder passenger_wsgi.py that shows “It works!” at the app’s URL. Open the URL now to confirm, before uploading your code.
2. Upload your Flask code
Put the project files in /home/USER/flaskapp, as a ZIP through File Manager or with Git. A minimal app.py:
import os
from flask import Flask
app = Flask(__name__)
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "change-me")
@app.route("/")
def index():
return "Hello from Flask on cPanel"
Don’t upload your local venv or .venv folder; the server’s environment is separate.
3. Edit passenger_wsgi.py
Replace the placeholder with this, so it imports your app as application:
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from app import app as application
If your app uses an application factory, replace the last line with:
from myproject import create_app
application = create_app()
4. Install packages inside the virtual environment
An example requirements.txt:
Flask
Flask-SQLAlchemy
PyMySQL
From the interface: on the app’s page, under Configuration files, type requirements.txt, click Add, then Run Pip Install.
Over SSH: copy the command shown at the top of the app’s page to enter the virtual environment; it looks like this. Then install:
source /home/USER/virtualenv/flaskapp/3.12/bin/activate && cd /home/USER/flaskapp
pip install -r requirements.txt
Never install with pip outside this environment; the app won’t see those packages.
5. Add environment variables
On the app’s page, under Environment variables, click Add Variable for each secret, such as SECRET_KEY and DATABASE_URL, then Save. Your code reads them with os.environ. A MySQL URL for a database on the same hosting looks like:
mysql+pymysql://cpuser_app:password@localhost/cpuser_app
If the password contains characters such as @ or /, URL-encode them.
6. Create tables or run migrations
Inside the virtual environment, run your project’s commands, for example:
flask --app app db upgrade
if you use Flask-Migrate. Alternatively, use Execute python script on the app’s page to run a script that creates the tables.
7. Restart and test
Click Restart on the app’s page after changing code, variables or packages, or run this in the app root:
mkdir -p tmp && touch tmp/restart.txt
Then open the URL. You should see your app instead of “It works!”.
8. Read the logs
Python errors and tracebacks go to the Passenger log file you set:
tail -n 50 /home/USER/logs/flaskapp.log
To see an import error directly, run python -c "import passenger_wsgi" inside the environment.
9. Background tasks
Passenger only runs the app in response to requests. For periodic jobs or always-on bots, use a cron job that runs a Python script from the same environment, such as /home/USER/virtualenv/flaskapp/3.12/bin/python worker.py. A full example is in run a Telegram bot with Python.
Troubleshooting
- “It works!” shows instead of your app:
passenger_wsgi.pywasn’t updated, or you didn’t restart. - ModuleNotFoundError: the package isn’t installed in the virtual environment, or
sys.pathdoesn’t include the app folder. See ModuleNotFoundError. - “externally-managed-environment”: you’re using the system
pipinstead of the environment’s. Enter the environment first; see pip externally managed. - “Web application could not be started”: an error at import time or a missing variable. See Passenger app error.
- mysqlclient fails to install: it needs C libraries to compile. Use PyMySQL instead; it’s pure Python.
- Changes don’t show up: Passenger keeps the loaded code in memory until you restart.
On ArabyHost
Python apps run on ArabyHost AI/Developer plans, with Python 3.9 to 3.12 through the CloudLinux selector and Phusion Passenger, SSH jailed in CageFS, Git, and background workers kept alive with cron. You can deploy from GitHub, by ZIP, or from Claude and Cursor through Araby MCP. Resources are shared with per-account limits, and there’s no Docker, root access or GPU. If the log doesn’t make the cause clear, the Araby AI assistant in the panel reads the error log and explains the fix.
FAQ
Do I need Gunicorn to run Flask on cPanel?
No. Phusion Passenger is the application server here and calls the application object in passenger_wsgi.py directly. Don't run Gunicorn or app.run() on the live site.
How do I connect Flask to a MySQL database on the hosting?
Create the database and user in cPanel, then use a connection URL such as mysql+pymysql://user:password@localhost/dbname with Flask-SQLAlchemy and PyMySQL. Keep the URL in an environment variable rather than in your code.
Can I run FastAPI the same way?
Passenger on cPanel runs Python apps through WSGI, while FastAPI is ASGI. You can wrap it with an adapter such as a2wsgi in passenger_wsgi.py; the FastAPI deployment guide covers the details.