Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Composer Global Configuration Private Repositories URL List

PHP Composer allows you to define it project's composer.json list of urls pointing to private repositories. Example:

{
    "require": {
        "vendor/my-private-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "[email protected]:vendor/my-private-repo.git"
        }
    ]
}

But whenever I create a new private repo I need to edit all my projects and add that new repo URL to their composer.json before I am able to request that new package.

Is there any global composer configuration where I could store URLs to all of my private repos or even better where I can globally set an URL pointing to a resource that will have a list of all my private repos and their URLs up to date?

like image 265
Jimmix Avatar asked Jan 29 '19 12:01

Jimmix


People also ask

Where is composer global config?

The composer config has the following optional parameters: --global(-g): This Operates on the global config file located at “$COMPOSER_HOME/config. json” by default.

Where is composer config json?

It should be in ~/. composer/auth. json .

How to connect to a private GitHub repository using composer?

So, composer can connect to our private repository using the personal access token provided. Read only permissions are sufficient for this personal access token as it is used by composer to only download the package from our private github repository. To create a personal access token on github,

How do I set all repositories in composer?

You could set all repositories in you Composer home directory (find where it is with composer config --global home ). There is a config.json file in which you can add all the global repositories (global on that machine for all your projects).

How do I authorize a private url in composer?

Option 1: Authorizing composer using auth.json file. This method is Recommended only for local development and not for production usage. If we are trying to download a package from a url which is private, Composer will look for authorization credentials for the private url in a file called auth.json.

Can I host my composer packages on Packagist?

If you are creating packages with in your organization and want to keep them private, You cannot host them on packagist.org. Composer provides private package hosting as a paid service on packagist.com. If you can afford the private packagist hosting, I recommend to use private packagist instead of hosting your private composer packages on github.


2 Answers

Use

composer config --global --editor

Then next to config add repositories with yours, e.g.

{
  config: {},
  repositories: [
    {
      type: vcs,
      url: [email protected]:vendor/package.git
    }
  ]
}
like image 69
Luboš Remplík Avatar answered Sep 25 '22 16:09

Luboš Remplík


You could set all repositories in you Composer home directory (find where it is with composer config --global home). There is a config.json file in which you can add all the global repositories (global on that machine for all your projects).

See the docs on this file: https://getcomposer.org/doc/03-cli.md#composer-home-config-json

Unfortunately, you cannot have a central managed way for this out of the box. You could look into Composer Satis for this. With Satis you can host a single repository that references where all your packages are located (e.g. Bitbucket, GitHub or otherwise).

like image 30
7ochem Avatar answered Sep 25 '22 16:09

7ochem