If you’re thinking about launching new applications this year, there are many good reasons to choose Heroku as your hosting platform. In addition to its ability to make deployment and environment configuration easy, Heroku provides a well-designed platform, tools, documentation, and an extensive add-on community.

Heroku’s superpower is managing your…


Laravel on Heroku — Tip #6

Laravel by default will save sessions into a directory on disk, which isn’t ideal, because Heroku uses an ephemeral filesystem (explained in Tip #5).

You have to use another session driver. Laravel ships with several great drivers out of the box:

  • Cookie
  • Database
  • Redis

In this example, we use Redis…


Laravel on Heroku — Tip #5

Photo by Markus Spiske on Unsplash

Laravel by default will log errors and messages into a directory on disk, which isn’t ideal, because Heroku uses an ephemeral filesystem, that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container-based systems, such as Docker, operate.

Change the log destination on Heroku:

heroku config:set LOG_CHANNEL=errorlog

Now you can tail the logs live:

heroku logs -t

That’s it. 🚀

Want more tips like these?

You should follow me on Twitter! And if you’re building on Heroku, you should check out AutoIdle — the automated way to save money on your staging and review apps.


Laravel on Heroku — Tip #4

Photo by Todd Quackenbush on Unsplash

Laravel has great documentation about deployment.

The most important part is optimization, which includes 3 parts:

  1. Autoloader Optimization
  2. Optimizing Configuration Loading
  3. Optimizing Route Loading

On Heroku, we also need these 3 optimizations.

Autoloader Optimization

We have to optimize Composer’s class autoloader with the following command:

composer install --optimize-autoloader --no-dev

Heroku already run…


Laravel on Heroku — Tip #3

Photo by Sonja Langford on Unsplash

Heroku has the free Heroku Scheduler, but this has two disadvantages:

  • it runs only every 10 minutes, every hour, or every day
  • you have to add your commands in there UI

Laravel comes with an amazing Task Scheduler.

To run Laravel scheduled jobs on Heroku you have to add a new command and run that as a process.

Create the Command app/Console/Commands/SchedulerDaemon.php:

You can generate this file with:

php artisan make:command SchedulerDaemon

Add the following line to your Procfile:

Add “-d memory_limit=512M” to use 512M instead of 128M RAM

Don’t forget to enable this process in the Heroku Dashboard:


Laravel on Heroku — Tip #2

On Heroku the release phase allows you to run certain tasks before a new release of your app is deployed.

Release phase can be useful for tasks such as:

  • Run the database migrations
  • Clear cache
  • Sending CSS, JS, and other assets from your app’s slug to a CDN or S3…

Laravel on Heroku — Tip #1

On Heroku, you get environment variables for PostgreSQL, Redis, e.g.

You shouldn't add manually environment variables on Heroku for Database (like DB_HOST, DB_PORT, e.g.) and Redis (REDIS_HOST, e.g.).

Because you have to change these if you upgrade/downgrade these Heroku add-ons.

And more importantly, Heroku can change these environment variables at any time.

A better solution would be, add the following lines at the beginning of config/database.php

Want more tips like these?

You should follow me on Twitter! And if you’re building on Heroku, you should check out AutoIdle — the automated way to save money on your staging and review apps.

AutoIdle — A Heroku Add-on

We are building a Heroku Add-on that helps you save money by automatically putting your non-critical apps to sleep after a period of inactivity.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store