DEV Community

Ellis
Ellis

Posted on

How to Installing a Laravel app on Heroku with Database?

Prerequisites :

  • Php and Laravel knowledge
  • Heroku user account
  • Heroku toolbet (Heroku CLI)
  • Git

Create the project

Any way you like, get your Laravel application initialized.

laravel new laravel-heroku
cd laravel-heroku
Enter fullscreen mode Exit fullscreen mode

Add your Procfile

As per the documentation, By default, Heroku serves the files from the root index. So to tell Heroku to serve the app from public/ directory, you have to make a Procfile.

web: vendor/bin/heroku-php-apache2 public/
Enter fullscreen mode Exit fullscreen mode

Initialize the git repo

OK, our code is ready to go. Let's get it into git.

git init
git add .
git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Create the Heroku app

Since you have the Heroku Toolbelt installed, you can create and modify your apps directly from the command line.

heroku create
Enter fullscreen mode Exit fullscreen mode

output:

± heroku create
Creating app... !
 ▸    Invalid credentials provided.
heroku: Press any key to open up the browser to login or q to exit:
Logging in... done
Logged in as me@email.com
Creating app... done, ⬢ app-name-here
https://app-name-here.herokuapp.com/ | https://git.heroku.com/app-name-here.git
Enter fullscreen mode Exit fullscreen mode

Add an APP_KEY
Generate a new key:

php artisan key:generate --show
Enter fullscreen mode Exit fullscreen mode

Copy the output of that, and then run this command:

heroku config:set APP_KEY=the_key_you_copied_here
Enter fullscreen mode Exit fullscreen mode

output:

Setting config vars and restarting ⬢ app-name-here... done, v3
APP_KEY: the_key_you_copied_here
Enter fullscreen mode Exit fullscreen mode

Deploy your code to the Heroku app

With Heroku, you push new code to your site by pushing to the heroku git remote.

git push heroku master

Enter fullscreen mode Exit fullscreen mode

output:

----> Launching... done, v3
       http://app-name-here.herokuapp.com/ deployed to Heroku
Enter fullscreen mode Exit fullscreen mode

Now it is deployed on heroku. And your laravel app is on http://app-name-here.herokuapp.com/ url.

Reference

Oldest comments (0)