Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 332
Gabf Hann Avatar asked Sep 25 '16 16:09

Gabf Hann


People also ask

What is private Packagist?

Private Packagist is a commercial package hosting product offering professional support and web based management of private and public packages, and granular access permissions.

Where does composer get packages from?

Composer downloads directly from the source, e.g. Packagist only knows those source and tells your composer instance where to go. It does this by downloading a bunch of json files from Packagist.org that have all the infos.

What is composer lock?

composer. lock records the exact versions that are installed. So that you are in the same versions with your co-workers. composer install. Check for composer.lock file.


1 Answers

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
like image 86
Katie Avatar answered Sep 21 '22 05:09

Katie