Skip to main content

php-composer-quickstart

Last updated on

Prerequisites

  • Ensure you have the PHP Composer CLI (composer) and Harness CLI installed on your local machine.
  • Access to a Harness account with appropriate permissions to create registries and connectors.

Create a PHP Composer Artifact Registry

private registry

This registry will serve as your private PHP Composer registry within Harness.


Configure an Upstream Proxy (Optional)

An upstream proxy allows your registry to fetch PHP Composer packages from external sources if they are not available locally.

Create an upstream proxy


Configure the upstream proxy in your registry

upstream proxy caching

If a PHP Composer package isn’t found in your Harness registry, the upstream proxy fetches it from an external registry like Packagist, reducing duplication and improving package resolution.


Publish & Install PHP Composer packages

Configure Authentication

Step 1: Generate an identity token for authentication

  1. In your Harness PHP Composer Artifact Registry, click Setup Client.
  2. Click Generate Token to generate an identity token.

Step 2: Configure Composer to use the token for authentication

composer config --global --auth http-basic.pkg.harness.io token <TOKEN>

Publish Package

Step 1: Create a Composer archive from your project

composer archive --format=zip

Step 2: Upload the Composer package to the Harness registry using Harness CLI

hc artifact push composer <REGISTRY_NAME> <FILE_PATH> --pkg-url pkg.harness.io

Install Package

Step 1: Add the private registry to your project's composer.json

"repositories": [
{
"type": "composer",
"url": "https://pkg.harness.io/pkg/<HARNESS_ACCOUNT_ID>/<PHP_COMPOSER_REGISTRY_NAME>/composer"
}
]

Step 2: Install a package using Composer

composer require <ARTIFACT_NAME>:<VERSION>