DEV Community

Ellis
Ellis

Posted on

1

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DevOps for Private APIs. With DreamFactory API Generation, you get:

  • Auto-generated live APIs mapped from database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️