Composer global config & private repositories

I’m using composer for what feels ages now. Composer is a great tool, and in my opinion everyone should use it.

That said, there are quite a few things about it not that well documented, in some cases because it is not that well organised, in others because it doesn’t mention everything.

For example, did you know that composer has a global configuration? And, do you actually know what you can configure there?
I knew it was there for a while, but i had not ever looked into what can be done with it.

Today i was looking for a way for the company i work for to add our private repository in a way that we don’t have to add it to every single composer.json file, but can configure the repository once and then just use it.

Googling for a solution actually led to a lot of places, but most of them just mentioned you can add it to your composer.json – so i decided to have a look what is actually in the global config:

composer config -g -l

the list of options configured then gave me a hint on what to google for, and i ended up with the right page in the composer manual:

i’m not sure why i didn’t find it before, maybe because with assuming the configs being in ~/.composer/ i was looking for configuration, not for the cli documentation

you can edit the global config by doing

composer config -g -e

or, if you want to solve the same problem as i wanted to solve, you can simply use this command and it will add it to your config yourself:

composer config -g repositories.myrepository composer http://myrepositoryhost/

I guess if you are using composer in a company/private environment this is a quite useful information.

I might or might not make another post with a few more hints on the other options.


One thought on “Composer global config & private repositories

  1. composer constantly ignores my custom repositories i added in that global config file. i always have to configure each project individually. this a really annoying workflow. what actually is that config.json for if its has no effect?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s