Composer: Using Private Repositories

By | May 23, 2019

Assalamualaikum / Hi,

Assuming you are having private Repositories in GitHub, which you want to use with your application.

The use case here is how you can use your private repositories, without relying to packagist.org?

Setup your composer.json file as following:

Do take note on line 51 , I have added custom repositories which point to my private repository in my GitHub.

Next, you need to generate your Personal Access Token in GitHub.

I set my scopes as following:

Once you have generate your token, copy the token – you might want to save it anywhere safe.

Now you have two options – either you want to use the token globally or only for particular application. For now, let’s do for single application.

In your project directory, type the following:

$ composer config github-oauth.github.com your-personal-access-token

Once you are done, you can run:

$ composer update
$ composer require nasrulhazim/my-private-repository

Now you are done! Congratulation!

If you want to use the Personal Access Token globally, just pass option -g in the composer config.

$ composer config -g github-oauth.github.com your-personal-access-token

Thanks!

2 thoughts on “Composer: Using Private Repositories

Leave a Reply

Your email address will not be published. Required fields are marked *

nine + 6 =