Get your Flask Python app live on Cpanel in 2 minutes with this guide

Em Fhal
CodePubCast
Published in
3 min readJan 16, 2023

Flask is a popular micro web framework for Python that allows you to easily create web applications and APIs. Cpanel is a web-based hosting control panel that allows you to manage your website and server. In this guide, we will show you how to get your Flask Python app live on Cpanel in just 2 minutes.

Before we begin, make sure you have the following:

  • A domain name and a web hosting account with Cpanel
  • A Flask app that you want to deploy
  • Your app’s code and dependencies (e.g. requirements.txt) in a zip file

First, log in to your Cpanel account. Look for the “File Manager” option and click on it. In the File Manager, navigate to the public_html folder, which is where your website’s files are stored.

Next, click on the “Upload” button and select the zip file containing your app’s code and dependencies. Once the file is uploaded, extract it by right-clicking on the zip file and selecting “Extract”.

requirements.txt

# This file is used by pip to install required python packages
# Usage: pip install -r requirements.txt

# Flask Framework
Flask==1.0.2

# Flask Packages
Flask-Script==2.0.5
Flask-SQLAlchemy==2.4.0

myapp.py

from flask import Flask
app = Flask(__name__)
application = app # our hosting requires application in passenger_wsgi

@app.route(“/”)
def hello():
return “This is Hello World!\n”

if __name__ == “__main__”:
app.run()

Next, edit the “passenger_wsgi.py” and remove everything there and add

from myapp import application

Finally, go back to the Cpanel setup python screen and one addition to the configuration file textbook “requirment.txt” and press add. next, click twice on run pip install and select rquiemnt.txt.

done

And that’s it! Your Flask Python app is now live on Cpanel. You can now access it by visiting your domain name in the browser. With this guide, you can now easily deploy your Flask app to Cpanel in just 2 minutes. Happy coding!

--

--