Skip to main content

Composer Repositories

Only available in Sonatype Nexus Repository Pro. Interested in a free trial? Start here.

Composer is a tool for dependency management in PHP. Declare the libraries your project depends on and Composer installs and updates them for you.

See Composer's documentation for details.

Note

Nexus Repository native Composer support does not support migration from the Community plugin.

Proxying Composer Repositories

Composer proxy repositories cache packages from privately hosted and public repositories.

To proxy a Composer repository, create a new Composer (proxy) as documented in Repository Management.

Minimal configuration steps are:

  • Define the proxy name. e.g. composer-proxy

  • Define the URL for remote storage. e.g. https://packagist.org/

  • Select a blob store for storage

Configure Composer Client

Update the composer.json file saved in the ~/.composer folder and set the repositories section to include a link to the Composer proxy in the Nexus Repository.

Example:

"repositories": [
 {
   "type": "composer",
   "url": "localhost:8081/repository/composer-proxy"
 }
],

Disabling Packagist.org

Disable the default Packagist.org repository by adding the following to your composer.json:

{
  "repositories": [
    {
      "packagist.org": false
    }
  ]
}

Configuring Authorization

When Nexus Repository requires authorization, Composer should have an auth.json file saved in the ~/.composer folder. Below is an example of setting the authorization configuration:

{
  "http-basic": {
    "localhost:8081": {
      "username": "admin",
      "password": "admin123"
    }
  }
}

Update the Repository_Base_URL to the base URL for your Nexus Repository.

See the Composer documentation on managing authentication.

Using an Unsecured HTTP Repository Server

Composer is configured by default only to allow secured proxies. This may be disabled when your repository is not configured with HTTPS. Add the following to your composer.json:

{
  "config": {
    "secure-http": false
  }
}

See the Composer documentation for details.

Clearing the Local Cache to Pull From Nexus Repository

Composer caches dependencies to speed up builds and reduce network usage. Run the following to clear the local cache:

composer clear-cache