Knowledge

How to use private dependencies in Composer?

When you create a project, you often use a pre-set library already written in PHP. Private dependencies can help you download these external packages/libraries. This article will tell you how to serve private projects in the Composer dependencies in Buddy.

Authorization with SSH key

  1. Generate a new pair of SSH keys in the terminal (make sure they're not secured by a passphrase):

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
  2. Add the private key to Environment variables in Buddy and enter id_rsa as the name.

    Adding private SSH key to EV
    Adding private SSH key to EV
  3. Authorize the public key in the repository.


Authorization with HTTP Basic Auth

  1. Add the environment variables with login and password to the repository:

    Adding login credentials to EV
    Adding login credentials to EV
  2. Enter the following command before composer install:

    http-basic.github.com ${AUTH_USER} ${AUTH_PASS}
    composer install
    

    If the host is different from GitHub, just change the first element to http-basic.gitlab.com / http-basic.bitbucket.org etc.


Authorization with OAuth token GitHub

  1. Generate a token in the GitHub settings. While adding, select the scope repo:

    Selecting scope of permissions in GitHub
    Selecting scope of permissions in GitHub
  2. Add an enviroment variable named GH_TOKEN and paste the value from the previous step:

    Adding GitHub token to EV
    Adding GitHub token to EV
  3. Enter the following command before composer install:

    composer config github-oauth.github.com ${GH_TOKEN} 
    composer install
    

Authorization with GitLab Token

  1. Generate a token in the GitLab settings. Make sure the expiration date is extended enough:

    Selecting scope of permissions in GitLab
    Selecting scope of permissions in GitLab
  2. Add an enviroment variable named GL_TOKEN and paste value from the previous step:

    Adding GitLab token to EV
    Adding GitLab token to EV
  3. Enter the following command before composer install:

    composer config gitlab-token.gitlab.com ${GL_TOKEN}
    composer install
    

Get started now

14 days of unlimited trial. No credit card required.