7

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

1 Answer 1

8

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
3
  • yea for some reason php composer.phar update doesnot work but php composer.phar install works... Idk why
    – Gabf Hann
    Sep 27, 2016 at 18:09
  • Weird, I haven't seen that problem. You might want to delete the lock file (or rename it so you have a backup). Then you can do a update to generate a fresh lock file and see if install then works properly, maybe composer is a bit confused :)
    – Katie
    Sep 27, 2016 at 19:28
  • what's the difference betwwen personal toke / ci cd token and github token ?
    – famas23
    Sep 13, 2020 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.