You’ll learn how to register a domain name, configure your DNS, and deploy a basic website using Heroku!
- GitHub account.
- Heroku account.
- Account with domain registrar of choice. This one is simple.
- Fingers to type with.
- Write a simple app in Python using Flask
- Run our app locally.
- Deploy said app to the cloud via Heroku.
- Register a domain.
- Setup DNS to point to our app.
- Clone this repo:
git clone [email protected]:michiganhackers/heroku-py-demo.git
- Install Virtualenv:
pip install virtualenv
(may needsudo
).
(If you're wondering, this is for creating an isolated python environment.) - Run
virtualenv venv --distribute
to start up a virtual environment. - Run:
source venv/bin/activate
to start up the virtualenv. - Install Flask:
pip install -r requirements.txt
.
Now we are ready to run it!
- Type
python server.py
to run the app. - Navigate to
http://localhost:3000/
- Notice if you make changes to the file the server will restart automatically.
Notes:
- The
Procfile
is used by Heroku to start your app. - Heroku uses
Foreman
to run your app, you can too! Tryforeman start
. - If you add new pip modules use
pip freeze > requirements.txt
before deploying. (This way Heroku knows what your dependencies are.) - More Heroku deployment details.
heroku login
heroku create [yourappname]
Make up a great app name.git push heroku master
(If you dont have an ssh key on Heroku see below.)
heroku ps:scale web=1
This gives your app oneweb worker
.heroku open
This will go to yourappname.herokuapp.com- Grab a beer.
SSH Key Upload:
- open new terminal window and type
cat .ssh/id_rsa.pub
- if no file exists type
ssh-keygen
then hit enter (dont name a file) - type a password if you want extra security. (Jack is wincing right now).
- type
cat .ssh/id_rsa.pub
again and copy only the printed lines. - go to your account page and paste in the ssh key.
source venv/bin/activate
python server.py
to run locally.
git commit -am "commit message"
git push heroku master
Update Heroku, no need to scale.
heroku open
I'd love it if this repo were a starting point for your next big project. Create a repo on GitHub, and reset the origin url with the new one it gives you.
git remote set-url origin [email protected]:you/your-repo.git
git push origin master
- Find a domain.
- Pay for the domain.
heroku domains:add www.example.com
- Add a DNS record with your provider's website:
CNAME | www.example.com | yourappp.herokuapp.com - More Heroku Domain Help