Laravel Logs in Heroku and more

Make it easy. Make it standard.


Yes, Heroku. If you don't know about Heroku, I recommend you to give it a try. I think it is a really good choice for small applications. Its free tier is basically the best. EC2 is a better option if you really need some real control and access to your virtual server but if you don't need that, I think Heroku will fit you perfectly.

The only thing you need to know about architecture is the concept of stack. A stack is a predefined bundle including operating system, language runtime and libs. Stack is normally autodetected on (git) deploy, you can set it manually, though.

Each time you deploy your project to heroku, it compiles a slug. It is an optimized (compressed and pre-packaged) version of your app to be distributed in a dyno manager (dynos are some sorf ot virtual filesystem) and type of application (and buildpack) is autodetected if buildpack is not manually set.

Ok, finally... Buildpacks are the way you customize your system. Heroku offers a standard set of official buildpacks but you can set your own (not easy stuff, btw).

Ok, please, c'mon... What's the problem?

The problem is you can not ssh heroku. But you need to see your application logs, eventually. Well, when you install your heroku toolbelt (a command-line tool) you can do things like this:

heroku logs -t

Nice! We're done! ... Well, no, not really. You will see dozens of lines there but probably you will not see you customs logs.

The reasson of that is heroku logs just pull any line in stdout and or stderr and your logs are actually written to a file.

You can create your custom buildpack to get this file and connect your logs to the heroku logs but creating a buildpack for that is just crazy. Also, using a custom buildpack is potentialy dangerous and I don't recommend it at all. I used a very good user-defined buildpack for a long time and I really appreciate the effort of Christoph Hochstrasser (a.k.a. CHH) but I think you may use the standard buildpack whenever is possible.

Here we go. A step-by-step recipe

  1. Remove any BUILPACK_URL and PATH from your heroku config

  2. heroku config:remove BUILPACK_URL
    heroku config:remove PATH

    Perfect, now we let heroku to detect the type of application and will detect our application as PHP whenever we have a composer.json file. Cool

  3. [Optional] Heroku auto-dectection could fail

  4. Maybe your a Gulp fan like me. Gulp is based on Node.js and forces us to set a package.json file. Heroku will think our application is a Node.js app because of this package.json file (otherwise ignore this step). In this case you will need to manually set the buildpack like this:

    heroku config:add BUILPACK_URL=

  5. You want to use nginx and some specific set up

  6. Sure, no problem. Create a file named "Procfile" in your root directory and type this line within:

    web: vendor/bin/heroku-php-nginx -C nginx.conf public

    Create this ngnix.conf in your root directory and set some directives there.

  7. PHP Extensions missed?

  8. Ok, spend 2 minutes to see which extension the buildpack is providing by default maybe you need some extra extension, yo can do it through your composer.json by adding lines to the require section


    "ext-gd": "*",

    "ext-mbstring": "*",


So, what about those missed logs?

Please, read this super good article. It is really interesting and a good reading about logging, addons like papertrail and so. I'll only add a couple of tips.

  1. Use start global.php and local.php

  2. In your /app/start/global.php


    $monolog = Log::getMonolog();

    $monolog->pushHandler(new Monolog\Handler\ErrorLogHandler());


    In your /app/start/local.php




    That way you'll log in files in your local environment and you get the logs in heroku!

I really recommend the use of papertrail to filter and explore logs.

Enjoy and remember!

Don't overcomplicate things