I assume that you already know how to use Git and Heroku. If you don’t, go http://try.github.com to learn Git, and download Heroku toolbelt, of course you need to install Git in your computer.
Heroku is a rock solid PaaS platform for you to host web apps easily. With the new update from Heroku for supporting composer and of course, Laravel. PHP lovers now have one more damn good hosting option for their favorite framework Laravel.
Ho shit I love Laravel, it’s better than meth.
Now I just going to explain a few tweaks that you need to do to Laravel before it runs on Heroku.
Step 0: Create a Laravel Project
So as usual:
$ cd ~/apps
$ composer create-project laravel/laravel app_name
Wait! If you do not understand the lines above, you probably need to learn how to use PHP Composer. There is a chance you don’t even know you should do this thing in Terminal (OS X) or Git Bash (Windows).
What we just did is that we have moved into ~/apps folder and created a Laravel project, with any name of the app you like lah.
Then the next thing we need to do is initiate a git repository for the app, and create a heroku app then push it up!
$ git init
$ git add .
$ git commit -m 'Initialised Laravel'
$ heroku create
$ git push -u heroku master
But wait! Heroku recognized that it’s a PHP app but couldn’t proceed because… composer.lock is not checked in!
Step 1: Unignore composer.lock
Turns out, by default, Laravel’s default .gitignore has composer.lock to be ignored. Open up .gitignore and delete the line with composer.lock in it.
Then we recommit the .gitignore and try to push again. This time, we get this:
So what just happened?
Turns out that by default, Heroku thinks that your project root folder should have index.php to serve as homepage. But Laravel is different, the homepage is actually inside public/ folder.
So how do we make heroku serve public/index.php instead?
We need to add a Procfile. A Procfile (process file) declares the processes of the app, you got like web processes (deal with web requests) and background processes (queues or workers that send e-mails, do mundane tasks so web requests don’t get slowed down).
Step 2: Procfile
To make the Procfile, just create a new file named… Procfile and put it in project root. Inside Procfile, just write:
web: vendor/bin/heroku-php-apache2 public
Recommit, and push. It should work now.