Wilfred Chukwu
Posted on August 24, 2020
I had issues the first time i wanted to deploy my flask app to heroku and i remember vividly searching for articles and youtube tutorials on how to host wep apps with heroku i wasted a lot of time on something rather simple to follow. so i am writing this this article to help ease your way to deployment of wep apps in heroku.
Before reading this article i already assume that you have:
- a free Heroku account.
- Python installed
- your project(codes) ready to be deployed
Heroku CLI Set up
In this step you need to install the Heroku Command Line Interface (CLI). You use the CLI to manage and scale your applications,view your application logs, and run your application locally.
vist heroku.com to download your operating system's cli
Once installed run this command line in the terminal
heroku login
you will be prompt to login for authentication
Preparing the app
if the app is on github clone the application so that you have a local version of the code but if its already in your local machine in the terminal run
cd yourproject/app folder name
if cloned from github after the first command then run:
pip install -r requirements.txt
Note: if you are using your own application, make sure you have added a requirements.txt file by running
pip freeze > requirements.txt
so that all the application dependencies are added.
Add gunicorn and Procfile
run
pip install gunicorn
update requirements.txt by running
pip freeze > requirements.txt
Now create a new file Procfile as name in the project folder
note: (P) must be uppercase
in Procfile add
web: gunicorn app:app
note:The first app represents the name of the python file that runs your application or the name of the module it is in. The second app represents your app name. For example if your application runs from a run.py file that looks like this:
run:app
Runtime.txt
create runtime.txt
and Add this in runtime
python-3.7.2 or the current python version you used for the app
Deployment
In the application folder run
heroku create appname of your choice
config database through heroku site and connect
then in the terminal run
heroku git:remote -a appname of your choice
git push heroku master
wait... after its done
to view your web app run
heroku open
wolah!! you have successfully deployed your app.
related articles
https://devcenter.heroku.com/articles/getting-started-with-python
https://medium.com/the-andela-way/deploying-a-python-flask-app-to-heroku-41250bda27d0
Posted on August 24, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.