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.

https://devcenter.heroku.com/articles/getting-started-with-php#scale-the-app

https://devcenter.heroku.com/articles/getting-started-with-php

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

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

Setup

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.
Email: dz@example.com
Password:
...

Prepare the App

$ git clone https://github.com/heroku/php-getting-started.git
$ 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
http://sharp-rain-871.herokuapp.com/ | https://git.heroku.com/sharp-rain-871.git
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 http://example.herokuapp.com, and git@heroku.com:example.git 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 https://github.com/heroku/heroku-buildpack-php

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.

Lumen

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

Source: https://devcenter.heroku.com/articles/getting-started-with-php#push-local-changes

Setting up config vars for a deployed application

https://devcenter.heroku.com/articles/config-vars

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

Source: https://devcenter.heroku.com/articles/git#deploying-code

http://www.phprs.com.br/2016/06/hospedando-aplicacao-php-no-heroku/

Manage multi-environments

https://github.com/meumobi/AMS.Connect/issues/86


Victor Dias

Sharing mobile Experiences

Follow me