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
- Interactive Guide
- Step-by-Step
- Navigate to the Artifact Registry module in your Harness project.
- Click on New Artifact Registry.
- In the Registry Type dropdown, select PHP Composer Registry.
- Provide a Registry Name.
- Your registry name must start with a letter and can include
lowercase alphanumerics,_,.and-.
- Your registry name must start with a letter and can include
- Optionally, add a Description and Labels for better organization.
- Choose visibility between Public and Private. By default, the visibility is set to Private.
- Click Create Registry to finalize.
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.
- Interactive Guide
- Step-by-Step
Create an upstream proxy
Configure the upstream proxy in your registry
Create an upstream proxy
- In the Artifact Registry module, click the dropdown next to New Artifact Registry and select Upstream Proxy.
- Choose PHP Composer Registry as the proxy type.
- Click Create Proxy to establish the connection.
Configure the upstream proxy in your registry
- In the Artifact Registry module, select an existing PHP Composer Artifact Registry.
- Select the Configuration tab.
- Under Advanced (Optional), select Configure Upstream.
- Select from the list of compatible proxies to add them to your registry.
- Click Save to save the configuration.
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
- In your Harness PHP Composer Artifact Registry, click Setup Client.
- 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>