Installing local composer packages
This tutorial will guide you on how to install a composer package in one of your other applications, typically used when working locally.
In this scenario my application is called demo/ and example/ is my package.
// Folder Structure
- ~/Sites
- demo/composer.json
- example/composer.json
Your composer package
The composer package I created is called josezenem/example
, the contents of the file can be found here:
{
"name": "josezenem/example",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"Josezenem\\Example\\": "src/"
}
},
"authors": [
{
"name": "Jose Jimenez"
}
],
"require": {}
}
Telling demo where to find the package
Next I have a directory called demo/ which holds the application that will import the package.
{
"name": "josezenem/demo",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"authors": [
{
"name": "Jose Jimenez"
}
],
"require": {}
}
The changes we will make is add the required package
"require": {
"josezenem/example": "dev-main"
}
we will add a "repositories" with the type of "path", and the url which is the path to the example package.
"repositories": [
{
"type": "path",
"url": "../example"
}
],
It should look like this:
{
"name": "josezenem/demo",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"authors": [
{
"name": "Jose Jimenez"
}
],
"repositories": [
{
"type": "path",
"url": "../example"
}
],
"require": {
"josezenem/example": "dev-main"
}
}
Once this is all complete, you can run composer install
or composer update josezenem/example
which will import your package locally via symlink.