Matomo Analytics

This guide will walk you through the process of installing a global auth.json file for Composer on an Ubuntu server. This file will be used to authorize access to private repositories, making it more convenient to manage private packages and repositories.

Prerequisites

Before proceeding, ensure that you have the following installed on your Ubuntu server:

  1. Ubuntu 20.04 or later
  2. Composer (Visit https://getcomposer.org/download/ for installation instructions)

Step 1: Create the global auth.json file

First, we need to create a global auth.json file in the Composer's configuration directory.

  1. Open your terminal.
  2. Run the following command to create the Composer configuration directory, if it doesn't already exist:
  3. mkdir -p ~/.config/composer 
  4. Navigate to the newly created directory:
  5. cd ~/.config/composer 
  6. Create the auth.json file using your preferred text editor, for example:
  7. nano auth.json 

Step 2: Configure the auth.json file

Now, we will configure the auth.json file with the necessary repository credentials. The file should follow the JSON format, containing a "http-basic" object and a "github-oauth" object if you are using both types of repositories.

Here's an example of an auth.json file:

{
  "http-basic": {
    "repo.example.com": {
      "username": "your-username",
      "password": "your-password"
    }
  },
  "github-oauth": {
    "github.com": "your-github-token"
  }
}

Replace the placeholders with your own credentials:

  1. For "http-basic" authentication, replace repo.example.com with the domain of your private repository, and enter your username and password.
  2. For "github-oauth" authentication, replace your-github-token with your personal GitHub access token.

Save and close the auth.json file. If you used nano, press Ctrl + X, then Y, and then Enter.

Step 3: Set the correct permissions

To ensure that only the owner can read and write to the auth.json file, set the appropriate permissions by running:

chmod 600 ~/.config/composer/auth.json 

Step 4: Verify the configuration

To verify that your auth.json file is correctly configured, run the following command:

composer config --global --list 

You should see the global config settings, including the path to your auth.json file.

You have successfully installed and configured a global auth.json file for Composer on your server. This will allow you to authorize access to private repositories with ease. Remember to keep your auth.json file secure, as it contains sensitive credentials.

28 March 2023 (last updated 1 year ago)

6233 views

Written by Dennis

Dennis brings over 6 years of hands-on experience in server management, specializing in optimizing web services for scalability and security.

Back to Deployment


Start free trial