Using a private Composer package with Laravel and Docker.

Categories: Development

Updated February 2025, removing the deprecated authentication method.

Developing packages for use with laravel is reasonably straightforward. But we don’t always want to make our code publicly available on Packagist.

Adding a custom repository to your composer.json file will allow us to pull code straight from your Github account rather than Packagist.

{
  "type": "project",
  "require": {
    "adampatterson/core": "dev-main"
  },
  "repositories": [
    {
      "type": "vcs",
      "url": "[email protected]:adampatterson/core.git"
    }
  ],
}

It’s common practice to place your source code in a src/ folder. You will also want to create your packages composer.json file with at least the following details…

{
    "name": "adampatterson/core",
    "description": "Some kind of Core package for an app.",
    "type": "library",
    "homepage": "https://github.com/adampatterson/app-core",
    "support": {
        "issues": "https://github.com/adampatterson/app-core/issues",
        "source": "https://github.com/adampatterson/app-core"
    },
    "autoload": {
        "psr-4": {
            "AdamPatterson\\Core\\": "src/"
        },
        "files": [
            "src/Helpers.php"
        ]
    },
    "authors": [
        {
            "name": "Adam Patterson",
            "email": "[email protected]"
        }
    ]
}

Running composer install should no prompt you for a token, in this case from GitHub.

Follow the on screen directions, generare your token. Paste it in your terminal and you should be good to go.

If you’ve installed the token globally you should find a file ~/.config/cd composer/auth.json


Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!