I had some problems when trying to deploy to Heroku with Laravel 5.1.*. See more about the problem at Pull.
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
curl -s https://gist.githubusercontent.com/3runoDesign/7c4c8652c7c4543c9a3b/raw/5bb673135c6498abf8512b623e3d362efcfbd59c/buildpacks > .buildpacks
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"
],
heroku config:set APP_ENV=production
heroku config:set APP_KEY=$(php artisan --no-ansi key:generate --show)
heroku config:set APP_DEBUG=false
git add .
git commit -m "Start"
git push heroku master #&& git push origin master
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
Aeeehoooo vlw, tive que fazer algumas mudanças por que meu git push pro heroku não estava funcionando mas consegui.