Flask Hosting: How to Run a Flask App in cPanel
- Ali GhanimatiAuthor
- Last updated
- 6 minutesReading time
- 642Views
- Ali Ghanimati
- Last updated:
- 6 min read
- 642 views
Your Flask app works perfectly on your laptop with flask run: a few pages, a form, maybe a small API. Now it’s time to put it on the internet so others can see it too. You might think that needs a VPS and Linux commands; but if your cPanel host has the Setup Python App tool, you can launch your Flask app without a terminal, in a few clicks!
In this tutorial you’ll see, step by step, how to run Flask in cPanel: what Flask hosting needs, how to create the Python app in cPanel, how to install Flask, where to put your code and where to start if you hit an error.
Short answer: in cPanel, open Setup Python App from the Software section and use Create Application to set the Python version, the app folder and its URL. In the app folder, create requirements.txt with one line,
flask, and install it with Run Pip Install. Put your Flask code in the startup file so that the app object is named application, then restart the app.
What does Flask hosting need?
Flask is a lightweight Python microframework: unlike Django, it has no built-in authentication or admin panel, and you add whatever you need yourself. To run on the internet, Flask needs a WSGI server; Flask’s own development server, the one behind flask run, is only for your own computer.
If you’re looking for Flask hosting, choose a cPanel host with CloudLinux and the Setup Python App tool. It creates a separate virtual environment (virtualenv) with the Python version you want for each app and runs the app with Passenger, through the host’s own web server. For heavy apps or work that must run constantly in the background, such as Celery queues, a VPS is the better home.
1. Create a Python app in cPanel
Log in to cPanel and click Setup Python App in the Software section. If you don’t know the login address, see How to Log In to cPanel.

On the page that opens, click CREATE APPLICATION.

Now fill in the app’s fields:
- Python version: pick the newest version on the list that works with your libraries. Old versions such as 3.8 no longer get security updates.
- Application root: the app’s folder name in your home folder, such as flaskapp. Don’t put it inside public_html, so your code can’t be downloaded over the web.
- Application URL: the domain or subdomain the app opens on. If you leave the box next to it empty, the app opens on the domain itself; with a path like app, it sits at yourdomain.com/app.
- Application startup file: the file Passenger runs. Left empty, passenger_wsgi.py is created.
- Application Entry point: the name of the WSGI object in that file; the default is application. It must match the variable name in your code exactly, and upper and lower case matter.

Click CREATE. The app folder is created with the startup file and the public and tmp folders. If you open the app’s address now, you’ll see a page saying It works! with the Python version; the app is ready and only your code is missing.
2. Install Flask with requirements.txt
Open File Manager from the Files section and go into the app folder, flaskapp in this example.


In this folder, create a file named requirements.txt and write each library on its own line. One line is enough to start: flask. Save the file.


Go back to Setup Python App and click the edit icon next to the app. In the Configuration files section, enter requirements.txt or its full path and click Add. In the full path, hostname stands for your hosting username, not your domain name:

Now click Run Pip Install so Flask is installed in this app’s virtual environment. If you have access to cPanel’s terminal, the command to enter that environment is shown at the top of the app’s page, something like source /home/user/virtualenv/flaskapp/3.12/bin/activate. After running it, pip install installs libraries into the same environment.
3. Put your code in the startup file
Open the startup file in File Manager and replace its contents with this code. We named the Flask object application so it matches the default Entry point:
from flask import Flask
application = Flask(__name__)
@application.route("/")
def home():
return "Hello from Flask on cPanel!"If you have an existing project where Flask is created in app.py under the name app, upload the files to the app folder and make this single line the whole content of passenger_wsgi.py:
from app import app as applicationRemove app.run() calls and debug mode from the code on the host; running the app is Passenger’s job, and debug mode is dangerous on a public site.
4. Run and test
Restart the app in Setup Python App and open its address in the browser. If you see your app’s text, you’re done! After every code change or new library, click Restart once more.

In the image above the browser shows a Not secure warning, because the site has no SSL certificate yet. Before you publish the app, get SSL for the domain so it opens over https; see How to Install SSL in cPanel.
Fixing common Flask errors in cPanel
- It still shows It works!: your code isn’t in the file the Application startup file points to, or you haven’t restarted the app.
- No module named ‘flask’: Flask isn’t installed in this app’s environment. Add requirements.txt under Configuration files, click Run Pip Install and restart.
- Error 500 or 503: in the app’s settings, set Passenger log file to a path like /home/user/flaskapp/passenger.log, reload the page and read the error text and line number in that file. If the error is about importing application, compare the Entry point name with the variable name in your code.
- The home page opens but other routes give 404: compare the Application URL with the address you open; if the app is installed in a subpath like /app, all Flask routes live under that /app.
FAQ
Does Django run on cPanel the same way?
Yes. For Django, give the path of the project’s wsgi.py as the Application startup file and set the Entry point to application. More tips, and running scheduled scripts with Cron Jobs, are in How to Run Python on Shared Hosting.
Can a Flask app connect to a MySQL database?
Yes. Create the database and its user in cPanel’s MySQL Databases section, add a library such as PyMySQL to requirements.txt and connect with the database name, username and localhost.
Python and Flask hosting at HiData
HiData’s professional cPanel hosting and high-traffic hosting can run Python, and launching a Flask app takes exactly these steps. Got a bigger app that needs background work or heavy libraries? A HiData VPS with full root access is the place for it!


