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?
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.
It should be in ~/. composer/auth. json .
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,
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).
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.
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.
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
}
]
}
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With