Skip to main content
in Composer

Require local projects from composer

Composer is a dependency management tool for PHP that allows developers to easily include and manage third-party libraries in their projects. One of the great features of Composer is the ability to require local packages. This can be useful in a number of different situations and can save developers time and effort when working with multiple projects.

There are several use cases where requiring a local package can be useful:

  1. Development of a package: When you are developing a package that you want to use in multiple projects, you can require the local version of the package in your other projects instead of pushing it to a remote repository. This can save time and effort as you don't have to go through the process of publishing your package every time you make a change.

  2. Sharing a package between projects: If you have multiple projects that rely on the same package, you can require the local version of the package in each project. This can be useful if you are working on a team and want to ensure that everyone is using the same version of the package.

  3. Testing a package: If you want to test a new version of a package before publishing it, you can require the local version in your project to see how it performs.

To require a local package, you will need to specify the path to the package in the "repositories" section of your composer.json file. Here is an example:

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

Note that you will need to run "composer update" any time you make changes to the local package, as Composer does not automatically detect changes to local repositories.

composer update

Requiring local packages can be a useful feature of Composer that can save time and effort when working with multiple projects or developing packages. With a few simple code examples, you can easily incorporate local packages into your project and take advantage of this powerful tool.

Related articles