Docs menu

Package managers

Composer on Primcloud: package sources, private repositories and credentials, and lockfiles.

On this page

PHP apps use Composer. Every build installs your dependencies with composer install, skipping require-dev; PHP on Primcloud shows the full command.

Package sources#

Composer installs from Packagist unless you add sources under repositories in composer.json:

composer.json
{
  "repositories": [
    {
      "type": "composer",
      "url": "https://repo.packagist.com/acme/"
    },
    {
      "type": "vcs",
      "url": "[email protected]:acme/private-package.git"
    }
  ],
  "require": {
    "acme/private-package": "^1.0"
  }
}

Every repository type Composer supports works the same as it does locally.

Private packages and registries#

Give Composer its credentials with a COMPOSER_AUTH secret holding a JSON object keyed by auth type:

{
  "http-basic": {
    "repo.packagist.com": { "username": "token", "password": "<token>" }
  },
  "github-oauth": {
    "github.com": "<token>"
  },
  "bearer": {
    "custom-registry.example.com": "<token>"
  }
}

Enter it on one line:

COMPOSER_AUTH={"http-basic":{"repo.packagist.com":{"username":"token","password":"..."}}}

Composer uses the github-oauth entry to clone private vcs repositories on GitHub; a personal access token with repo scope is enough.

Warning

Don't commit an auth.json to your repo, where anyone with access to the repo can read it. Use COMPOSER_AUTH instead.

Lockfiles#

If composer.json has dependencies in require, commit a composer.lock beside it, or the build fails. A composer.json that's empty or only has require-dev needs no lockfile.

The lockfile also records the PHP version and extensions Composer resolved, which is what the build installs, so production runs the same PHP as your machine.

Run composer update whenever you change require, require-dev, or the php requirement, and commit both files. If they disagree, for example after editing one by hand or an unresolved merge conflict, Composer warns that the lock file is not up to date with composer.json and the install can fail. composer update --lock regenerates the lockfile without changing versions it doesn't need to.