Breaking News

How to deploy Laravel on Heroku ? - Beginner's Guide !

Getting Started with Laravel on Heroku

As you all know Heroku is a cloud platform as a service (PaaS). It offers us to deploy our web applications on Heroku. Heroku supports Node.js, Java, PHP, Ruby, Scala, Clojure, Python and Go programming languages.

Today we will see how we can deploy a Laravel framework on Heroku? Laravel is the is today's best PHP framework. YO !!, Let's get into the direct deployment process of Laravel.



  • PHP knowledge with some Laravel.
  • A Heroku user account. Signup.
  • Composer Installed on your computer (if not then download and install from here).
  • Heroku CLI installed on your computer. Heroku CLI is a command line tool used to deploy and manage your project on Heroku. Download and Install here.



Now I hope you have all prerequisites ready. Let's start with creating fresh Laravel application.We need to login to Heroku account through Heroku CLI, as follows:

$ heroku login

Enter email address and password then.

Now, use the following command to create Laravel project:

$composer create-project laravel/laravel --prefer-dist YourApp'sName

When it ends up with creating Laravel project just CD into the project folder.

$ cd YourApp'sName

It’s now time to initialize a Git repository and commit the current state:

$ git init

$ git add


$git commit -m "New laravel Project"

Now its time to deploy the Laravel application to Heroku. But, before tha, We need to create Procfile

Procfile tells Heroku what command to use to launch the web server with the correct settings.

Use the following command to create the Procifile and commit the changes.

$ echo web: vendor/bin/heroku-php-apache2 public/ Procfile
$ git add .
$ git commit -m "commit procfile"

Up till now, we have created a Laravel project, Now to deploy a Laravel project to Heroku we must create Heroku Application, as follows.


$ heroku create YourApp'sname 

If you do not give your applications name then Heroku will generate a random name for you.

The next important step is setting a Laravel encryption key. This key is used to encrypt the Laravel sessions and other information.


$ php artisan key:generate --show  -> Use this key in next step.
$ heroku config:set APP_KEY= paste the key here, generated in above step.

One more most important step, edit the .gitignore file which is present in your Laravel project folder. Remove the word .env and save the .gitignore file.


Next, it’s time to deploy to Heroku:


$ git push heroku master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 379 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> PHP app detected
remote: -----> Resolved 'composer.lock' requirement for PHP to version 5.6.14.
remote: -----> Installing system packages...
remote:        - PHP 5.6.14
remote:        - Apache 2.4.10
remote:        - Nginx 1.6.0
remote: -----> Installing PHP extensions...
remote:        - mbstring (composer.lock; bundled)
remote:        - zend-opcache (automatic; bundled)
remote: -----> Installing dependencies...
remote:        Composer version 1.0.0-alpha10 2015-04-14 21:18:51
remote:        Loading composer repositories with package information
remote:        Installing dependencies from lock file
...
remote:          - Installing laravel/framework (v5.1.19)
remote:            Downloading: 100%
remote:
remote:        Generating optimized autoload files
remote:        Generating optimized class loader
remote:        Compiling common classes
remote: -----> Preparing runtime environment...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing... done, 74.5MB
remote: -----> Launching... done, v5
remote:        https://mighty-hamlet-1982.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/YourApp'sname.git
   1eb2be6..1b70999  master -> master


Yoo! We deployed our Laravel Application on Heroku. Now Hit the following command to open the Laravel application.


$ heroku open


What You Can Do Now?

Subscribe to my newsletter and follow my blog and Support me.

Or Like us on facebook to get updates on my new posts!


No comments