Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploy Heroku [Laravel 5.2.*]

I had some problems when trying to deploy to Heroku with Laravel 5.1.*. See more about the problem at Pull.

Creating application and deploying to Heroku

First of all we will create a laravel project and then we deploy in heroku.

laravel new nome_app

or

composer create-project --prefer-dist laravel/laravel nome_app

Set GIT.

git init

Create app to Heroku.

heroku create name_app

So far not much has changed, right? The .buildpacks and Procfile files are files specific to Heroku, they are what make the server configuration. The app_boot.sh is a shell that will run when setting up the server.

Now let's set buildpack from our server using the heroku-buildpack-multi. So let's specify what kind of server we want to join (PHP and NodeJS).

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git

Set Buildpacks:

curl -s https://gist.githubusercontent.com/3runoDesign/7c4c8652c7c4543c9a3b/raw/5bb673135c6498abf8512b623e3d362efcfbd59c/buildpacks > .buildpacks

Create APP Boot

curl -s https://gist.githubusercontent.com/3runoDesign/7c4c8652c7c4543c9a3b/raw/bdc5e201a7949c6d90c53ee2fd12dd164a173247/app_boot.sh > app_boot.sh

Create Procfile

curl -s https://gist.githubusercontent.com/3runoDesign/7c4c8652c7c4543c9a3b/raw/2dec75e90b8d8c9ac165b412ec7d2b18861136c9/Procfile > Procfile

All files created, now we need to configure the composer.json.

...
"scripts": {
  "post-install-cmd": [
    "php artisan clear-compiled"
  ],
  "post-update-cmd": [
    "php artisan clear-compiled"
  ],

Set environment variables

heroku config:set APP_ENV=production
heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)
heroku config:set APP_DEBUG=false

Deploy

git add .
git commit -m "Start"
git push heroku master #&& git push origin master

Database

Adicionar ClearDB (MySQL)

heroku addons:create cleardb:ignite

Na documentação do Heroku, lá sugere usar algo como. Veja aqui.

Só que eu particulamente não gosto, então faço assim:

Ao adicionar o ClearDB ele criar por padrão na variável de ambiente chamada CLEARDB_DATABASE_URL, para você ver o seu valor:

heroku config:get CLEARDB_DATABASE_URL

Veja como é composta a url: mysql://{USERNAME}:{PASSWORD}@{HOST}/{DATABASE}?reconnect=true;

Como desenvolvedor é preguiçoso, criei uma bash básica, onde eu passo a URL e ela me retorna as váriaveis:

#!/bin/bash

proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url=$(echo $1 | sed -e s,$proto,,g)
user="$(echo $url | grep @ | cut -d: -f1)"
host=$(echo $url | sed -e s,$user@,,g | cut -d/ -f1)
pass="`echo $url | sed -e s,$user:,,g | cut -d@ -f1`"
host="`echo $url | sed -e s,$user:$pass@,,g | cut -d/ -f1`"
database="$(echo $url | sed -e s,$user:$pass@$host/,,g | cut -d? -f1)"

echo "
heroku config:set DB_HOST=$host
heroku config:set DB_DATABASE=$database
heroku config:set DB_USERNAME=$user
heroku config:set DB_PASSWORD=$pass
"

agora basta você criar o seu bash e chamar

#!/bin/bash
# Artisan commands
/app/.heroku/php/bin/php /app/artisan clear-compiled
/app/.heroku/php/bin/php /app/artisan optimize
# Boot up!
vendor/bin/heroku-php-apache2 public/
https://github.com/heroku/heroku-buildpack-nodejs
https://github.com/heroku/heroku-buildpack-php
web: sh app_boot.sh
worker: php artisan queue:listen
@IsTheJack

This comment has been minimized.

Copy link

@IsTheJack IsTheJack commented Sep 23, 2015

Opa... Muito obrigado... Isso me ajudou bastante...

@ymhuang0808

This comment has been minimized.

Copy link

@ymhuang0808 ymhuang0808 commented Oct 12, 2015

Hope that the file is able to be translated into English language.

@3runoDesign

This comment has been minimized.

Copy link
Owner Author

@3runoDesign 3runoDesign commented Mar 27, 2016

@ymhuang0808 what's up... sorry for the delay! i will go to english!

@IsTheJack que bom man.

@lucasprogamer

This comment has been minimized.

Copy link

@lucasprogamer lucasprogamer commented Jun 8, 2016

Aeeehoooo vlw, tive que fazer algumas mudanças por que meu git push pro heroku não estava funcionando mas consegui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.