Heroku is a popular PaaS that allows you to deploy your application’s in no time. But, learning how to do that can be confusing, especially for PHP developers. In this tutorial I’ll cover basic steps which will help you to deploy your Laravel 4 application on Heroku. First let’s download Laravel:
composer create-project laravel/laravel --prefer-dist laravelAfter that, enter in laravel directory:
cd laraveland initialize new git repository:
git initNow, create .gitignore file and put everything you want to ignore from git tracking. You can use Laravel’s default .gitignore file, just remove composer.lock from it:
/bootstrap/compiled.php/vendorcomposer.phar.env.*.php.env.php.DS_StoreThumbs.db/.ideaAnd make a commit:
git add -Agit commit -m 'Initial commit'I assume that you have installed the Heroku Toolbelt, if you don’t have Heroku Toolbelt installed then just look at the install instructions and then continue with this tutorial.
Now, you need to login:
heroku loginyou need to enter your credentials and we’re ready to go. Let’s create our app:
heroku create shop-up --region eu --stack cedar --buildpack https://github.com/heroku/heroku-buildpack-phpheroku create command is used to create application called shop-up, with region parameter you can select region, stack parameter allows you to select on which stack you want to deploy your application and finally with buildpack parameter we can specify which buildpack we want to use for our application. In this case I used Heroku’s default PHP buildpack, and you can use whatever you want.
After executing this command we get following message:
Creating shop-up... done, region is euBUILDPACK_URL=https://github.com/heroku/heroku-buildpack-phphttp://shop-up.herokuapp.com/ | git@heroku.com:shop-up.gitGit remote heroku addedNow, you just need to create Heroku Procfile. You need to tell Apache2 web server that document root of your application is public/. Procfile should be placed in the root folder of your application. We just need to add one line to it:
web: vendor/bin/heroku-php-apache2 publicCommmit changes and push you application to heroku repository:
git add Procfilegit commit -m 'added Procfile'git push heroku masterAfter minute or two, you should get a message that tells you that your application is now deployed to Heroku:
Generating optimized autoload files Generating optimized class loader-----> Preparing runtime environment...-----> Discovering process types Procfile declares types -> web-----> Compressing... done, 70.2MB-----> Launching... done, v11 http://shop-up.herokuapp.com/ deployed to HerokuAnd that’s it. Here is list of some useful commands that you may need:
heroku run php artisan <some-artisan-command>heroku run composer <some-composer-command>heroku apps # List of your Heroku applicationsheroku config --app <your-app> # List of your config/environment variables for specified applicationheroku addons --app <your-app> # List of add-ons you have enabled on your applicationIn the next tutorial I’ll show you how you can add and use PostgreSQL database on your Heroku instance. Stay tuned.