Deploy Flask App or Host Flask Application on cPanel
Deploying a Flask application on cPanel might sound tricky, but it’s actually quite straightforward when you break it down step by step. If you’re looking for an easy way to host your Python-based Flask web app on a shared hosting environment, cPanel is a great choice.
Table of Contents
In this ultimate guide, we’ll walk you through everything you need to know about deploying a Flask application on cPanel, from setting up your environment to configuring the webserver properly.
Why Deploy Flask App on cPanel?
cPanel is widely used for shared hosting and offers a user-friendly interface to manage websites, databases, and applications. Here are a few reasons why deploying Flask on cPanel is a great choice:
- Affordable Hosting: Many shared hosting plans come with cPanel at no extra cost.
- User-Friendly: The GUI makes it easy to manage files, databases, and settings.
- Built-in Features: cPanel comes with MySQL, cron jobs, and other useful tools.
- No Need for a Dedicated Server: You don’t need to manage a VPS or a dedicated server to deploy your Flask app.
Prerequisites
Before we start, make sure you have:
- A cPanel Hosting Account – Ensure your hosting provider supports Python applications.
- Flask Installed Locally – You should have a working Flask app on your local machine.
- A Domain or Subdomain – You need a domain or subdomain pointing to your cPanel account.
- SSH Access (Optional) – Some hosting providers like Aveshost allow SSH access, making deployment easier.
- Python Version Supported – Check if your hosting provider live Aveshost supports Python 3.x.
Watch the Video Tutorial
For an easier way to deploy Flask application on cPanel, watch the YouTube video below. If you prefer a detailed, step-by-step written guide, continue reading.
Step 1: Log in to cPanel
First, log in to your cPanel account. The URL usually looks something like this:
https://yourDomainName.com/cpanel or directly from your Aveshost account dashboard
Once inside, you’ll see various tools for managing your hosting account.
Step 2: Create a Python Application in cPanel
- Scroll down to the Software section and click on Setup Python App.

- Click Create Application and select:
- Select Python Version (preferably 3.9+).
- Application root:
/home/yourusername/yourprojectname(or any preferred directory). For instance, if your application’s root folder is named flaskapp and you are using your primary domain, the application root directory will be flaskapp. In this guide, we are using a subdomain, so our application root becomes flask.hostplus.top. - Application URL: Select the domain or subdomain you want to use.
- Application startup file: Leave it blank for now (we’ll configure this later).
- Application Entry point: Leave it blank for now (we’ll configure this later).

- Click Create and note the Virtual Environment Path displayed.

Step 3: Upload Your Flask Application
You can upload your Flask app project in two ways:
Option 1: Upload via File Manager
- Go to Files section in the cPanel and click File Manager.
- Inside the File Manager, navigate to the application root directory you set in Step 2.
- Click Upload and select your Flask project’s
.zipfile.

- Extract the
.zipfile after uploading. Right-click the uploaded ZIP file and select ‘Extract‘ to unzip it.
Ensure that all files are located in the flask.hostplus.top folder (or any preferred directory). If they are not, navigate to the extracted folder, select all files, and move them to the flask.hostplus.top folder or your chosen directory.
Note: Be sure to delete the .zip file after extraction
Suggested Reading: How to Upload Your Website (in 3 Simple Steps)

Option 2: Clone from GitHub
- Open Terminal from cPanel or connect via SSH.
- Navigate to the application directory:
cd /home/yourusername/yourprojectname
- Clone your project from GitHub:
git clone https://github.com/yourusername/your-repository.git
Step 4: Install Dependencies
Your Flask project has dependencies listed in requirements.txt. You can install them in two ways:
Method 1: Using Setup Python App Page
- Go back to Setup Python App.
- Click the Edit button for your application.
- Find the Configuration files section and enter:
requirements.txtthen click Add button

- Click “Run Pip Install”, then select the requirements.txt file to install the dependencies.
Method 2: Using the Terminal
- Activate the virtual environment: copy and paste the Virtual Environment Path from Step 2 or manually activate the virtual environment.
Virtual Environment Path from Step 2
source /home/cpusrplus/virtualenv/flask.hostplus.top/3.11/bin/activate && cd /home/cpusrplus/flask.hostplus.top
Or manually activate the virtual environment
source /home/yourusername/virtualenv/yourprojectname/3.x/bin/activate
- Install dependencies: In the Terminal, navigate in your project directory and run the command to install the dependencies;
pip install -r requirements.txt
Step 5: Configure Application Startup File
- Within your Flask application’s root directory, modify either
app.pyorconfig.pyto include this:
application = app
- Open Setup Python App and locate your application.
- Find the Application Startup File section: Enter the location of your
app.pyfile. In my case, it isapp.py, then save and restart the application.

- Alternatively, you can keep the
passenger_wsgi.pyfile and follow the rest of the process to modify it accordingly. - Locate and edit the
passenger_wsgi.pyfile in your project’s root directory. Overwrite its existing content with the sole line:
from app import app as application
- Save the file
- Go back to your Setup Python App page and restart your application
Step 6: Test Your Flask Application
Open your browser and visit your Flask app’s URL. If everything is set up correctly, your application should be live!
Step 7: Fix Common Deployment Issues
Even with correct setup, you may encounter some common errors. Below are solutions to the most frequent problems:
1. Application Error (500 Internal Server Error)
Solution:
- Check the error logs (
stderr.log). - Ensure that
requirements.txtis correctly installed. - Verify that the startup file is correctly set.
2. Module Not Found Error
Solution:
- Activate the virtual environment and reinstall dependencies:
source /home/yourusername/virtualenv/flaskapp/3.x/bin/activate pip install -r requirements.txt
3. File Permission Issues
Solution:
- Ensure the correct file permissions are set using:
chmod -R 755 ~/flaskapp
4. Debugging Your Flask App
Solution:
- Review
stderr.login the Flask application project folder.
Setting Up a MySQL Database (Optional)
If you want use MySQL Instead of SQLite3:
- Create a MySQL database in cPanel.
- Create a database user and assign it to the database.
- Update your Flask application’s configuration to use the database.
For a step-by-step guide on creating a MySQL database in cPanel, follow this illustrated tutorial: How to Set Up a MySQL Database & User in cPanel (2 Easy Methods).
1. Install MySQL Connector in Your Flask Environment
Since cPanel supports Python virtual environments, do the following:
- Open cPanel and navigate to Terminal.
- Activate your Python virtual environment if you have one:
source /home/your-cpanel-username/virtualenv/flaskapp/3.x/bin/activate
(Adjust the path based on your Python version and environment name)
- Install
mysql-connector-pythonorPyMySQL
pip install mysql-connector-python
OR
pip install PyMySQL
2. Update Your Flask Application
Modify your Flask application to use MySQL instead of SQLite.
- Edit
app.pyorconfig.pyand update the database URI:
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://your_db_user:your_db_password@localhost/your_db_name'
- Save the file
For a step-by-step guide on using MySQL instead of SQLite3, follow this: How to Use MySQL instead of SQLite3 in a Flask Application
Final Thoughts
Deploying a Flask application on cPanel might seem challenging at first, but by following these steps, you can have your web app up and running smoothly. Whether you upload via File Manager or use GitHub, install dependencies through cPanel or the terminal, the process remains straightforward if you adhere to best practices.
If you still encounter issues, reach out to your hosting provider’s support or check Flask and cPanel documentation for troubleshooting tips.
Now that your Flask app is live, what will you build next? 🚀
Suggested Reading:
- How to Deploy Django App on cPanel (The Ultimate Guide)
- How to Deploy Angular App on cPanel: CSR & SSR Guide
- How To Deploy a Node.js App on cPanel (The Ultimate Guide)
- How to Deploy Laravel Project on cPanel
- 50+ Essential Git Commands (With Downloadable Cheat Sheet)
- How to Set Up a PostgreSQL Database and User in cPanel
- How to Set Up a MySQL Database & User in cPanel (2 Easy Methods)
- How to Buy cPanel Hosting for Your Website: Beginner’s Guide
Frequently Asked Questions (FAQs)
What are the prerequisites for deploying a Flask app on cPanel?
You need a cPanel hosting account that supports Python applications, a working Flask app locally, a domain or subdomain pointing to your cPanel account, SSH access (optional but helpful), and a Python version supported by your hosting provider (preferably Python 3.x).
How do I create a Python application in cPanel for my Flask app?
In cPanel, go to the Software section and click ‘Setup Python App’. Click ‘Create Application’, select your Python version (3.9+ recommended), set the application root directory, choose your domain or subdomain for the Application URL, and leave the startup file and entry point blank for later configuration.
What are the methods to upload my Flask application files to cPanel?
You can upload via File Manager by navigating to your application root directory, uploading a .zip file of your project, and extracting it. Alternatively, you can clone from GitHub using the Terminal or SSH by navigating to your application directory and running ‘git clone’ with your repository URL.
How do I install dependencies for my Flask app on cPanel?
You can install dependencies using the ‘Setup Python App’ page by editing your application, adding ‘requirements.txt’ in the Configuration files section, and clicking ‘Run Pip Install’. Or, use the Terminal: activate your virtual environment, navigate to your project directory, and run ‘pip install -r requirements.txt’.
How do I configure the application startup file for Flask on cPanel?
Modify your app.py or config.py to include ‘application = app’. Then, in the ‘Setup Python App’ page, enter the location of your app.py file in the Application Startup File section, save, and restart the application. Alternatively, edit the passenger_wsgi.py file to contain ‘from app import app as application’ and restart.