How to Use a Private GitLab Repository as a Composer Dependency

The Composer documentation provides instructions for using a private GitHub or BitBucket repository as a dependency, but not GitLab. Here's what you need to know.

Create a personal access token

Create a personal access token, as per the GitLab documentation. Set the token scope to api.

Add your personal access token to Composer

Register your personal access token with Composer:

composer config \
  --auth "your-token" \
  --no-ansi \

If you prefer to do this manually, create a file at ~/.composer/auth.json, and add the following content:

  "gitlab-token": {
    "": "your-token"

Tell Composer where to find your package

By default, Composer searches for packages in the official Packagist repository. Override this by adding the GitLab repository to your composer.json:

  "repositories": [
      "type": "vcs",
      "url": ""

Require the package

Require the package in the usual way:

composer require project-name/repo-name