Thursday 3 March 2016

Deploy Django app on Heroku (Quick Guide)

Heroku is a platform as a service type cloud. It supports many languages like -

Python    |    php    |     Go   |     Scala    |     Ruby on Rails    |  Node.js   |    Java

 

 

 Here i am discussing about how to deploy your django app on heroku. So I am considering that your django app is ready to deploy...

 

Things you should learn before deploy -

1 - PostgreSQL (Heroku only support postgresql ,it must be installed locally on PC).

2 - Virtualenv (It creates a virtual environment, which separates required dependencies from all installed dependencies ).  [  pip install virtualenv ]

3 - Procfile (It is a simple text file , which declares the command to start the app).

4 - Dynos , requirement.txt file.

5 - Git and Github.


Steps to deploy -  

> Download HEROKU-TOOLBELT from heroku website.

> Open the heroku CLI and run these commands ---
       
$ git clone https://github.com/heroku/python-getting-started.git
$ cd python-getting-started
> It will create a folder in your local machine along with requirement.txt file.
        Folder PATH in local machine -- C:\Users\shivam\python-getting-started

> Create app on heroku cloud with random name - ( Ex - lit-bastion-5032)

$ heroku create
Creating lit-bastion-5032 in organization heroku... done, stack is cedar-14
http://lit-bastion-5032.herokuapp.com/ | https://git.heroku.com/lit-bastion-5032.git
Git remote heroku added
> Now push your project to heroku -
$ git push heroku master
Counting objects: 232, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (217/217), done.
Writing objects: 100% (232/232), 29.64 KiB | 0 bytes/s, done.
Total 232 (delta 118), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-2.7.11
remote:      $ pip install -r requirements.txt
remote:        Collecting dj-database-url==0.4.0 (from -r requirements.txt (line 1))
remote:          Downloading dj-database-url-0.4.0.tar.gz
remote:        Collecting Django==1.9.2 (from -r requirements.txt (line 2))
remote:          Downloading Django-1.9.2-py2.py3-none-any.whl (6.6MB)
remote:        Collecting gunicorn==19.4.5 (from -r requirements.txt (line 3))
remote:          Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
remote:        Collecting psycopg2==2.6.1 (from -r requirements.txt (line 4))
remote:          Downloading psycopg2-2.6.1.tar.gz (371kB)
remote:        Collecting whitenoise==2.0.6 (from -r requirements.txt (line 5))
remote:          Downloading whitenoise-2.0.6-py2.py3-none-any.whl
remote:        Installing collected packages: dj-database-url, Django, gunicorn, psycopg2, whitenoise
remote:          Running setup.py install for dj-database-url: started
remote:            Running setup.py install for dj-database-url: finished with status 'done'
remote:          Running setup.py install for psycopg2: started
remote:            Running setup.py install for psycopg2: finished with status 'done'
remote:        Successfully installed Django-1.9.2 dj-database-url-0.4.0 gunicorn-19.4.5 psycopg2-2.6.1 whitenoise-2.0.6
remote:
remote:      $ python manage.py collectstatic --noinput
remote:        58 static files copied to '/app/gettingstarted/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 39.3M
remote: -----> Launching...
remote:        Released v4
remote:        http://lit-bastion-5032.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To git@heroku.com:lit-bastion-5032.git
 * [new branch]      master -> master

> Running app with scale web=1  
$ heroku ps:scale web=1

 > Congratulations ....app is deployed NOW.
     Run this command to open your app in browser.
$ heroku open

No comments:

Post a Comment

Shivam Kumar Chauhan - Web developer