Gabf Hann
Gabf Hann

Reputation: 350

Composer to download private GitHub repositories

I cannot download github private repos with composer

php composer.phar update 

I get the following error

The "https://api.github.com/repos/company/private1" file could not be downloaded (HTTP/1.1 404 Not Found)

but i can easily download these private repos using git clone

Composer.json

"repositories": [
    {
        "type": "vcs",
        "url": "[email protected]:company/private1.git",
        "options": {
            "ssh2": {
                "username": "githubusername",
                "pubkey_file": "/home/username/.ssh/id_rsa.pub",
                "privkey_file": "/home/username/.ssh/id_rsa"
            }
        }
    },
    {
        "type": "vcs",
        "url": "[email protected]:company/private2.git",
        "options": {
            "ssh2": {
                "username": "githubusername",
                "pubkey_file": "/home/username/.ssh/id_rsa.pub",
                "privkey_file": "/home/username/.ssh/id_rsa"
            }
        }
    }
],

"require": {
    "php": ">=5.4.3",
    "zendframework/zendframework": ">2.1.3",
    "doctrine/mongodb-odm": "dev-master",
    "doctrine/doctrine-mongo-odm-module": "dev-master",
    "company/private": "dev-master",
    "company/private2": "dev-master"
}

I tried with this but it doesnot work

SSH2 PECL is also enabled.

I have also created config file vim ~/home/.ssh/config

with the following details

host www.github.com
User githubusername
HostName github.com
IdentityFile /home/username/.ssh/id_rsa

but still i cannot download the private repos using composer

Upvotes: 7

Views: 4337

Answers (1)

Katie
Katie

Reputation: 2693

In your composer.json file, you do not need the options in your repository section, just the type and url.

SSH

Over on GitHub, under Profile...Settings, there is a SSH and GPG Keys tab. This is where you load up the public side of your SSH key to access GitHub from your machine (where the private key is stored).

See their documentation Generating an SSH Key which steps you through this process. It also steps you through the SSH Agent storage for the private side of the key.

Personal Access Tokens

When you invoke composer install if you have not set up an access token, but need one, Composer will prompt you to generate it and a URL to use to accomplish this. You can use that URL and it will generate a once-seen API token that you then load up on composer to access GitHub. From the GitHub website:

Personal access tokens function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS.

If you don't see this automatic prompt, then here is how to do it manually:

  • Go to GitHub...Settings...Personal access tokens
  • Press the Generate new token button
  • Enter something meaningful to you in the Token Description
  • Check the repo checkbox (it will automatically check the three checkboxes underneath)
  • Press the Generate token button at the bottom of the page
  • Copy the token

Back on your server, tell composer about the token:

  • composer config -g github-oauth.github.com <token>
  • composer install

Upvotes: 8

Related Questions