W3docs

Composer require local package

To require a local package in Composer, you can use the "path" option in the "require" section of your project's composer.json file.

To require a local package in Composer, you must define it in the repositories section of your composer.json file using the path type, and then reference it in the require section with a version constraint (e.g., *, dev-main, or a specific version). For example:

Example of requiring a local package in Composer

{
    "repositories": [
        {
            "type": "path",
            "url": "path/to/local/package"
        }
    ],
    "require": {
        "vendor/local-package": "*"
    }
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can also configure the repository via the command line before installing the package:

Example of requiring a local package by command-line tool in Composer

composer config repositories.local path path/to/local/package
composer require vendor/local-package "*"

It's also possible to use a symlink instead of copying files. In that case, add the symlink option inside the path repository definition in your composer.json file. Note that paths are resolved relative to the composer.json file, and symlink: true is optional (Composer copies files by default):

Example of using a symlink in Composer

{
    "repositories": [
        {
            "type": "path",
            "url": "path/to/local/package",
            "options": {
                "symlink": true
            }
        }
    ],
    "require": {
        "vendor/local-package": "*"
    }
}

Then you can install your local package as usual.

Example of requiring a local package in Composer after using a symlink

composer require vendor/local-package "*"