|
1 | 1 | # How to deploy server to Heroku
|
2 | 2 |
|
3 |
| -Here are the steps: |
| 3 | +### Steps |
4 | 4 |
|
5 |
| -* We need to install heroku on our machine.Type the following in your linux terminal: |
| 5 | +* We need to install heroku on our machine. Type the following in your linux terminal: |
6 | 6 | * ```wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh```
|
7 | 7 | This installs the Heroku Toolbelt on your machine to access heroku from the command line.
|
8 |
| -* Next we need to login to our heroku server(assuming that you have already created an account).Type the following in the terminal: |
| 8 | +* Next we need to login to our heroku server (assuming that you have already created an account). Type the following in the terminal: |
9 | 9 | * ```heroku login```
|
10 |
| - You will see the following output: |
11 |
| - Enter your Heroku credentials. |
12 |
| - |
13 |
| - Password (typing will be hidden): |
14 |
| - |
15 |
| -* Once logged in we need to create a space on the heroku server for our application.This is done with the following command |
| 10 | + * Enter your credentials and login. |
| 11 | +* Once logged in we need to create a space on the heroku server for our application. This is done with the following command |
16 | 12 | * ```heroku create```
|
17 |
| -* We need to initialize our git repository and push the master branch of our repository to heroku.Type: |
18 |
| - * ```git init``` |
19 |
| - If the commit isn't changed to master we need to do so by typing the following commands on terminal: |
20 |
| - * ```git add -A``` |
21 |
| - * ```git commit -m "Initial Commit."``` |
22 |
| - * ```git push origin master``` |
23 |
| -* Next we create our requirements.txt file using the pip command: |
24 |
| - * ```pip freeze > requirements.txt``` |
25 |
| -* The next step is creating a Procfile. This can be done by using a production ready web server called gunicorn.The contents of the Procfile will be: |
26 |
| - * ```web: gunicorn <app>:app``` |
27 |
| - Here, the <app> will be replaced by the name of the application without the .py at its end.Basically a Procfile tells heroku what to name our process which runs our web application. |
28 |
| -* Before deploying to heroku, make sure that the app works locally on the designated port. |
29 |
| -* Finally we deploy the code to heroku.Its very simple, just type: |
30 |
| - * ```git push heroku master``` |
31 |
| - At the end of the process a URL will be generated where our flask application will run. |
| 13 | +* Once the app is created, now it's time to set the `DATABASE_URL` env var. |
| 14 | + * ```heroku config:set DATABASE_URL=postgresql://postgres:start@localhost/test``` |
| 15 | +* After setting env vars, create the heroku database. |
| 16 | + * ```heroku addons:create heroku-postgresql:hobby-dev``` |
| 17 | + * ```heroku pg:promote <HEROKU_POSTGRESQL_COLOR_URL>``` |
| 18 | +* Then we deploy the code to heroku. |
| 19 | + * ```git push heroku master``` or |
| 20 | + * ```git push heroku yourbranch:master``` if you are in a different branch than master |
| 21 | +* Finally, time to create tables on the server. Also in case of model updates, run the following command - |
| 22 | + * ```heroku run migrate``` |
0 commit comments