Create Account on Heroku, by default, your app is deployed on a free dyno. Free dynos will sleep after a half hour of inactivity (if they don’t receive any traffic). This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally.

This tutorial will work if you have PHP, git and composer installed - check that it’s there:

$ php -v
$ composer -V
$ git --version


Install the Heroku Command Line Interface (CLI), also called “heroku toolbelt”.

Log in using the email address and password you used when creating your Heroku account:

$ heroku login
Enter your Heroku credentials.

Prepare the App

$ git clone
$ cd php-getting-started

Heroku uses Composer for dependency management in PHP projects, and the composer.json file indicates to Heroku that your application is written in PHP.

Deploy the App

Create an app on Heroku, which prepares Heroku to receive your source code:

$ heroku create
Creating sharp-rain-871... done, stack is cedar-14 |
Git remote heroku added

When you create an app, a git remote (called heroku) is also created and associated with your local git repository. Heroku generates a random name (in this case sharp-rain-871) for your app, or you can pass a parameter to specify your own app name. To create a new app named “example”, run $ heroku create example, the app will be available at, and is the remote git repository URL;

Now deploy your code:

$ git push heroku master

Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows: $ heroku open

Heroku doesn’t recognize my Laravel app as PHP app heroku buildpacks:set

View logs

Heroku treats logs as streams of time-ordered events aggregated from the output streams of all your app and Heroku components, providing a single channel for all of the events.

$ heroku logs --tail

PHP Application Logging

Logging, then, is simply a matter of directing output to stdout or stderr - Heroku does the work of aggregating this across all the app and system components. View the web/index.php file to see how the Monolog service is configured to write its output to stderr.


The Lumen framework uses the Monolog library, which can be configured in app/bootstrap.php:

$app->configureMonologUsing(function($monolog) {
    $monolog->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr', \Monolog\Logger::WARNING));
    return $monolog;

Define a Procfile

Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app.

The Procfile in the example app you deployed looks like this: web: vendor/bin/heroku-php-apache2 web/

Declare app dependencies

Heroku recognizes an app as PHP by the existence of a composer.json file in the root directory. The demo app you deployed already has a composer.json, and it looks something like this:

  "require" : {
    "silex/silex": "^1.3",
    "monolog/monolog": "^1.4",
    "twig/twig": "^1.8",
    "symfony/twig-bridge": "^2"
  "require-dev": {
    "heroku/heroku-buildpack-php": "*"

The composer.json file specifies the dependencies that should be installed with your application. When an app is deployed, Heroku reads this file and installs the appropriate dependencies into the vendor directory. Your PHP app can then make use of the dependencies after a simple require: require('../vendor/autoload.php'); Run the following command to install the dependencies, preparing your system for running the app locally: $ composer update

Push local changes

First, add the modified files to the local git repository:

$ git add .

Now commit the changes to the repository:

$ git commit -m "Demo"

Now deploy, just as you did previously:

$ git push heroku master


Setting up config vars for a deployed application

Push different local Git branches to Heroku/master

Branches pushed to Heroku other than master will be ignored by this command. If you’re working out of another branch locally, you can either merge to master before pushing, or specify that you want to push your local branch to a remote master. To push a branch other than master, use this syntax: git push heroku yourbranch:master


Manage multi-environments

Victor Dias

Sharing mobile Experiences

Follow me