Tutorial for installing Heroku's command-line tool, and launch an example Django website.
This is for brand new Python users, including coding class students who want a simple and to-the-point guide on getting Heroku working on their system to launch Python websites.
This guide assumes you already have fundamental Bash and git knowledge.
This guide does not support Windows. It assumes you use either macOS or Ubuntu GNU/Linux.
Heroku is a company that will run an HTTP server application for you, and expose it to the internet.
They will do the heavy lifting of installing PyPI dependencies and making sure the right HTTP requests get to your servers (routing), you in turn need to only make sure your application is properly configured. Also important: They have a "freemium" payment model, where there is a "free-tier" that is great for learning without spending any money.
Heroku is now a subsidiary of SalesForce, and in turn rents its server space according to an agreement with Amazon Web Services.
Heroku (the business) - a company that will run your HTTP server application for you, and expose it to the web.
heroku (the CLI command) - A tool that Heroku the company has developed
which we will use for interacting with your Heroku account, and launching
heroku app - One particular application you are running on a Heroku server.
heroku add-on - Extra stuff your application needs, such as databases or media file services. These might cost money, and might be provided by a third party.
Now that you know a little about Heroku, it's time to install their CLI tool on your system and get used to using it.
First, go to the Heroku.com website and sign up for an account. Remember your username and password, you will be using it in a moment.
You may want to add in your credit card information -- although optional, it unlocks more free apps and add-ons at once even if you never buy anything.
Either use the Ubuntu Software Center (search for Heroku and click Install), or run the following command:
sudo snap install --classic heroku
Run the following command:
brew install heroku/brew/heroku
Login to Heroku (should only have to do this once):
For every web project you are working on, if you want to publish it, you should create for it a Heroku app.
Heroku acts a little like GitHub: They provide a remote Git server that we can push to. So, when you create an app, you are also creating a remote repo to store your code (much like GitHub).
Whenever Heroku receives code from us via a
git push, they will then try to
run that code on their servers, and expose it to the world.
For this tutorial, this very repo contains an example Django project you can
launch! Go ahead and
git clone this repo, to use it as your example Django
project to launch.
Already have a Django project? If you started it using
django-admin startproject, then follow this guide instead.
Every time you want to launch a brand new Python project, you will need to create a new Heroku app for it. These are the steps to both create a new heroku app, and link your git repo to it.
Go to the directory of your project.
Procfile. If you are using this example Django repo, you will already have a
Procfile. This tells Heroku which file is the main "entry point" to your server, in other words, which file to run to kick everything off.
requirements.txt). Again, if you are using this example, you will already have a
Important: Your project MUST be in a git repository.
git clonethis repo, then you are good on this front, also.
Pipfile, and manage.py are all at the "top level" next to
Create a new Heroku Application on your account for your project. This
command should be executed within your git project directory:
# You should see both "origin" twice and "heroku" twice (4 lines) when running # the following git command: git remote -v
If all went well, you are good to go! Deploy your app to Heroku:
git push heroku master
If it's working, you should see text like "Python app detected", then after a 30 seconds or so, something like this:
remote: -----> Launching... remote: Released v4 remote: https://secure-lake-12038.herokuapp.com/ deployed to
That strange URL "secure-lake-12038" will be a different combo of random words and numbers for you, but will be the URL of your new app! Click on that link or copy and paste it into your browser to see your application live for the world to see.
As you work on your project, after every change that you want to test on
Heroku, make a commit (
git add -A,
git commit -m) and then repeat the
previous last step (
git push heroku master).
By default, they pick a weird, random domain name, but you can customize it later if you want to have a custom name, or even a purchased domain name.
If you want to launch code to Heroku, it must be in a brand new commit. So, whenever you want to relaunch to the world, you will need to create a new commit.