This article shows the step to setup composer to install private Github repository.


On Github

1) Go to settings -> Developer Settings -> Personal Access Tokens -> Fine-grained tokens

2) Clicks on the "Generate new token" button.

3) Select an expiry period

4) Select a specific repo.

5) Provide "Contents" read-only access.

6) Generate and copy the token.


For Local Machine

1) Setup composer auth config by using the following command.

php composer.phar config -g github-oauth.github.com <token>

2) Or from the auth.json directly.

$ pico ~/.composer/auth.json
{
  "github-oauth": {
    "github.com": "github_pat_xxxxx"
  }
}

For Remote Deployment Server

1) Create a key-pair for the repository.

ssh-keygen -t ed25519 -C "For repo2"

2) Setup SSH Config.

$ pico /etc/ssh/ssh_config.d/repo2.conf

Host repo2
HostName github.com
User git
IdentityFile ~/.ssh/key2

3) Add key2.pub as deployment key on Github.

4) Setup git Config to rewrite the host

pico ~/.gitconfig

[url "git@repo2:org-name/ori-name.git"]
	insteadOf = git@github.com:org-name/ori-name.git