Skip to content

Composer and dependencies

Composer

Composer build is supported out of the box. If a composer.json file is detected at the root of your project, dependencies are installed during the build phase with --no-interaction --no-progress --no-scripts --no-dev flags. To override the base flags (--no-interaction --no-progress --no-scripts), set the CC_PHP_COMPOSER_FLAGS environment variable.

To install development dependencies, set CC_PHP_DEV_DEPENDENCIES to install. This removes the --no-dev flag independently of CC_PHP_COMPOSER_FLAGS.

Set CC_COMPOSER_VERSION to select the Composer version: 1, 2 (default) or lts (maps to 2.2).

Use a local Composer version

If you put a composer.phar file at the root of your project, it will be used to install dependencies.

You can perform your own composer.phar install by using the Post Build hook.

Example of a composer.json file:

{
    "require": {
        "laravel/framework": "4.1.*",
        "ruflin/Elastica": "dev-master",
        "shift31/laravel-elasticsearch": "dev-master",
        "natxet/CssMin": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/timothylhuillier/laravel-elasticsearch.git"
        }
    ],
    "autoload": {
        "classmap": [
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds"
        ],
        "psr-0": {
            "SomeApp": "app"
        }
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev"
}

Development Dependencies

Development dependencies are not automatically installed during the deployment. Set CC_PHP_DEV_DEPENDENCIES to install to include them. Set it to skip or leave it unset to exclude them.

GitHub rate limit

Sometimes, you can encounter the following error when downloading dependencies:

Failed to download symfony/symfony from dist: Could not authenticate against GitHub.com

To avoid failed dependency downloads caused by GitHub API rate limits during deployment, configure an OAuth token in your Composer configuration file or in a separate file as described in the Composer FAQ (API rate limit and OAuth tokens).

You can find more documentation about Composer configuration in the Composer schema reference.

Private Composer repositories

Composer can authenticate with private package repositories through the COMPOSER_AUTH environment variable. Its value is a JSON object containing Composer authentication settings, such as HTTP Basic, OAuth or an access token.

For example, to use Private Packagist, add its repository to your composer.json, replacing ORGANISATION with its short name:

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://repo.packagist.com/ORGANISATION"
    },
    {
      "packagist.org": false
    }
  ]
}

Then define COMPOSER_AUTH for your application with the username and token provided by Private Packagist:

{
  "http-basic": {
    "repo.packagist.com": {
      "username": "PACKAGIST_USERNAME",
      "password": "PACKAGIST_TOKEN"
    }
  }
}

Composer reads this variable automatically during composer install. Never commit credentials to your repository. If you use a local auth.json file, add it to .gitignore. See the Composer authentication documentation for other providers and authentication methods. For a private Git repository accessed over SSH, configure a private SSH key instead.

Post-build hook example

You use Artisan to manage your project and you want to execute artisan migrate before running your app.

To do this, use a post build hook by setting the following environment variable on your Clever application:

CC_POST_BUILD_HOOK=php artisan migrate --force

Note

You must add the execute permission to your file (chmod u+x yourfile) before pushing it.

Last updated on

Did this documentation help you ?