Deploy Laravel on Heroku

  • Published on

  • View

  • Download

Embed Size (px)


<p>Deploy Laravel on Heroku</p> <p>About MeEric Van Johnson PHP Developer, Architect and an Organizer of SDPHP</p> <p>Twitter: @shocmIRC: @shocm</p> <p>Laravel 101We start with a standard Laravel deployment </p> <p>And then a cd into our project directory</p> <p>Unlock you lockWe want to remove composer.lock from .gitignore </p> <p>Heroku ProcfileYou can configure Heroku server by leveraging a Procfile. We will use this to update our doc root to point to our /public directory</p> <p>Giter DoneNext we initiate our Git repo and commit some changes. </p> <p>Use the --forceYour Laravel application will complain if it doesnt have a log file and its unable to create one once deployed to Heroku. So we will create it now and force add it to the repo</p> <p>Commit to your choices in lifeNow we can do a git commit of our project.</p> <p>Heroku TimeYoull need to have a Heroku account and have the Heroku Toolbelt installed and configured. Great place to get started:</p> <p></p> <p>Well flash forward past this </p> <p>Spinning up HerokuWe create our Heroku instance and deploy our repo to it.</p> <p>Check out your awesome appAt this time we have our basic Laravel Application deployed and can view it.</p> <p>Add layers to the ApplicationLets update our routes, add a controller and add a view like a normal application.</p> <p>app/routes.phpapp/controllers/HelloController.phpapp/views/hello/index.blade.phpCheck out your awesome appCommit, push to Heroku and go to the new route.</p> <p>Adding PostgreSQL to your appWhy PostgreSQL and not MySQL?</p> <p>Heroku doesnt have native MySQL supportIn Heroku world, PostgreSQL is a first class citizen. There is a solution that allows you to add a MySQL to your Heroku app called ClearDB addon if you really want it. Since we are using Laravel and Eloquent, we dont actual care what our datastore is.Adding PostgreSQL (Part 2)Adding PostgreSQL is as simple as running a command. </p> <p>A peek at the configLets see what was assigned to us</p> <p>Modify start.phpWe are going to edit bootstrap/start.php to better detect environments </p> <p>Create Heroku ConfigurationsNext we create configuration files specifically for Heroku at the following path </p> <p>Configure DatabaseAlso be sure to update app/config/database.php and define PostgeSQL'default' =&gt; 'pgsql',</p> <p>Commit and pushapp/config/heroku/database.phpCreate APP_ENV VariableRemember we are detecting which environment we are in, in start.php using the variable APP_ENV. We will need to create and add that variable to our Heroku environment. </p> <p>Create a migrationNow we create a migration using the normal Laravel commands.</p> <p>Commit and PushRun migrationAfter we push our new migration we need to run the migration in the Heroku environment.</p> <p>Check migration was successful</p> <p>Enjoy Life</p> <p>START CODING!</p>