Configure Composer With Nexus
Configure Composer client to connect to a Composer proxy, hosted, or group repository in Nexus Repository. Note that you must create a Composer repository in Nexus before configuring your Composer client to connect to it. Refer to Create a Composer Repository.
Configure the Composer Client
Update the composer.json file saved in the ~/.composer folder. Set the repositories section to include the Nexus Repository URL.
Use the following syntax:
"repositories": [
{
"type": "composer",
"url": "<Repository_Base_URL>/repository/<REPOSITORY_NAME>"
}
],Where,
<Repository_Base_URL>- Base URL for your Nexus Repository instance.<REPOSITORY_NAME>- Name of the Composer repository.
For example:
"repositories": [
{
"type": "composer",
"url": "example.nexus.com/repository/composer-proxy"
}
],Disable Packagist.org
Disable the default Packagist.org repository by adding the following configuration to your composer.json file:
{
"repositories": [
{
"repo.packagist.org": false
}
]
}Where,
repo.packagist.org- The defaultPackagist.orgrepository.false- Disables the repository.
Configure Authorization
When Nexus Repository requires authorization, save an auth.json file in the ~/.composer folder.
{
"http-basic": {
"<Repository_Base_URL>": {
"username": "<USERNAME>",
"password": "<PASSWORD>"
}
}
}Where,
<Repository_Base_URL>- Base URL for your Nexus Repository instance.<USERNAME>- Your Nexus Repository username or usertoken name code.<PASSWORD>- Your Nexus Repository password or usertoken pass code.
For example:
{
"http-basic": {
"example.nexus.com": {
"username": "admin",
"password": "admin123"
}
}
}Update Repository_Base_URL to the base URL for your Nexus Repository.
For more information, see Composer authentication management.
Use an Unsecured HTTP Repository Server
Composer is configured by default to allow only secured proxies. You can disable this requirement when your repository is not configured with HTTPS. Add the following configuration to your composer.json file:
{
"config": {
"secure-http": false
}
}Where,
secure-http- Controls whether Composer requires HTTPS.false- Allows Composer to connect to a repository that is not configured with HTTPS.
For more information, see Composer configuration documentation.