---
title: How to deploy a Flask App in cPanel
description: "Each hosting package in [Truehost Cloud](https://truehost.co.ke/webhosting-in-kenya/) allows hosting of Python Applications. Flask and Django top the Python frameworks people prefer. In this guide we will learn how to deploy a Flask Application in cPanel. ## **Prerequisites** -Flask App already created…"
url: "https://truehost.com/support/knowledge-base/how-to-deploy-a-flask-app-in-cpanel/"
updated: "2024-06-07"
---

# How to deploy a Flask App in cPanel

Each hosting package in [Truehost Cloud](https://truehost.co.ke/webhosting-in-kenya/) allows hosting of Python Applications. Flask and Django top the Python frameworks people prefer. In this guide we will learn how to deploy a Flask Application in cPanel.

## **Prerequisites**

-Flask App already created on your computer using Python 3

-Flask App has a requirements.txt file ready. This can be created on your localhost by running the command below in the directory where your flask files reside:

$ pip3 freeze >> requirements.txt

## A. **Create a Python App in cPanel**

1. **Login** to cPanel

2. Navigate to **Setup Python App** icon and click it.

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel1.png)

3. Click **Create Application**

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel2-1024x292.png)

4. Fill in the form as follows then click**Create**

**Python version**– Select the Python version you need. We will use Python 3.8. If unsure, use the latest Python3 available.

**Application root** – This is the folder where you will put your website files e.g static and template folders etc

**Application URL** – This is the link people will use to access your application eg truehost.co.ke, truehost.co.ke/blog, portal.truehost.co.ke etc.

**Application startup file**– This is the file that should be run to load your application eg app.py, main.py etc

**Application Entry point** – This is the function that should be run to display your site. Its contained in your startup file under route(“/”)

**Passenger log file** – This is the file where errors will be logged. Helps with debugging and fixing errors

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel4-1024x500.png)

5**. Stop the Application.** You will restart it after upload files.

## B. **Upload your application files**

Once you create an application as described above, a ***virtualenv*** will be created. A folder called **appfiles** will be created as well under **File Manager.**

1. In cPanel, go to **File Manager**

2. Access **appfiles** folder

3. On your computer and create a zip file containing your template folder, static folder, requirements.txt and python files.

4. Click **Upload** under **appfiles** folder and upload your zip files.

5. Once uploaded, extract the files

## C. **Update*****main.py*****and*****passenger_wsgi.py*****files**

1. Open the main.py file and add the line below under app = Flask(__name__) line

***application = app***

2. Open the passenger_wsgi.py and delete the content in it then add the line below and **Save**

***from main import application***

## **D. Import modules in requirements.txt file**

1. In cPanel, got to **Setup Py****t****hon App**.

2. Under **Configuration files**, type in requirements.txt and click **Add**

3. Click **Run Pip Install**

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel3-1024x267.png)

4. Once the modules are installed, you can **Start the Application**

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel5-1024x264.png)

Hurray! Your app is now live.

## Troubleshooting

1. We're sorry, but something went wrong.
   You may see the page below when trying to run your application

![](https://truehost.co.ke/support/wp-content/uploads/2020/11/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-1024x496.png)

In cPanel, python, ruby and nodejs applications run via Phusion Passenger. The page above indicates you app run into an error and could not be loaded, but it does not show the exact error message as the app is in production. Your app users don’t need to see the python error.

As such, to fix, you need to check the Apache logs (Check Errors icon under Metrics) and passenger log file you configured while creating the application in Step A above. Some of the causes of the error above and their solutions are:

| **Issue** | **Solution** |
| --- | --- |
| Incorrect file/folder permissions | All files should be 0644 and folders 0755 permissions |
| Mod Security in cPanel | [Turn off Mod Security in cPanel](https://truehost.co.ke/support/knowledge-base/turn-mod-security-off/) |
| Incorrect database configuration | If your site runs on a database, supply the correct connection details |

2. Incomplete response received from application

One cause of this error is that, your passenger_wsgi.py file was over writen on restarting the application. Hence the content we put in there was removed. The solution is just to paste back the line below then restart the app.

from main import application
