Composer下载私有GitHub存储库

Gab*_*ann 5 php git ssh github composer-php

我无法下载与作曲家的github私人回购

php composer.phar update 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

无法下载" https://api.github.com/repos/company/private1 "文件(未找到HTTP/1.1 404)

但我可以轻松下载这些私人回购使用 git clone

Composer.json

"repositories": [
    {
        "type": "vcs",
        "url": "git@github.com: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": "git@github.com: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"
}
Run Code Online (Sandbox Code Playgroud)

我试过这个,但它不起作用

SSH2 PECL也启用了.

我还创建了配置文件 vim ~/home/.ssh/config

具有以下细节

host www.github.com
User githubusername
HostName github.com
IdentityFile /home/username/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

但我仍然无法使用composer下载私人回购

Kat*_*tie 6

在您的composer.json文件中,您不需要存储库部分中的选项,只需要typeurl.

SSH

在GitHub上,Profile...Settings有一个SSH and GPG Keys标签.这是您加载SSH密钥的公共端以从您的计算机(存储私钥的位置)访问GitHub的地方.

请参阅他们的文档生成SSH密钥,它将引导您完成此过程.它还会引导您完成密钥私有端的SSH代理存储.

个人访问令牌

composer install如果您没有设置访问令牌但需要访问令牌,则调用时,Composer将提示您生成它以及用于完成此操作的URL.您可以使用该URL,它将生成一个曾经见过的API令牌,然后您可以在composer上加载它以访问GitHub.来自GitHub网站:

个人访问令牌的功能类似于普通的OAuth访问令牌.可以通过HTTPS使用它们代替Git的密码.

如果您没有看到此自动提示,那么以下是如何手动执行此操作:

  • GitHub...Settings...Personal访问令牌
  • Generate new token按钮
  • 在中输入有意义的内容 Token Description
  • 选中repo复选框(它会自动检查下面的三个复选框)
  • 按下Generate token页面底部的按钮
  • 复制令牌

回到你的服务器上,告诉作曲家有关令牌的信息:

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