Deploying a Flask app on cPanel is slightly different from a standard VPS because cPanel uses Phusion Passenger to manage Python applications. This article is a step-by-step guide to getting a Flask application live.
1. Create the Python Application
First, you need to tell cPanel to set up a Python environment for your domain.
- Log in to cPanel and find the Software section.
- Click Setup Python App.
- Click Create Application.
- Configure the settings:
- Python version: Select the latest (best is 3.11).
- Application root: The folder name where your code will live (e.g.,
myapp). - Application URL: Select your domain and leave the path blank (for the homepage).
- Application startup file: Set this to
passenger_wsgi.py(cPanel expects this). - Application Entry point: Set this to
application.
- Click Create. You will see a command at the top like
source /home/user/virtualenv/myapp/.../activate. Copy this command.



2. Upload Your Flask Project
- Go to File Manager and enter your application root folder (
myapp). - Upload your project files (your
app.py,static/,templates/, andrequirements.txt). If you do not have a requirements.txt file, see this article on creating a requirements.txt file - Crucial Step: Create a file named
passenger_wsgi.pyin the root folder. This file acts as the bridge between cPanel and Flask. Paste the following code:
import sys, os
# Add your project directory to the sys.path
sys.path.insert(0, os.path.dirname(__file__))
# Import your Flask app object.
# If your file is app.py and your Flask instance is 'app', use:
from app import app as application
3. Install Dependencies
You need to install Flask and any other libraries into the virtual environment.
- Open the Terminal in cPanel (under the “Advanced” section).
- Paste the source command you copied in Step 1 and hit Enter. This enters your app’s virtual environment.
- Run the following commands:
pip install --upgrade pip pip install -r requirements.txt If you don't have a requirements file, just run: pip install flask
4. Final Configuration & Restart
- Go back to Setup Python App.
- Under Configuration files, type
requirements.txtand click Add, then click Run Pip Install. (This is a GUI alternative to the Terminal step). - Click the Restart button at the top of the page.
Posted in
CPanel, Knowledgebase, Web and Email Hosting
Dzinaishe Mpini
