Using Composer Create Project with a local repository

TL;DR: You need to pass the location of the local folder as a repository and then make sure you set the “–prefer-dist” value to “@dev”. Just replace everything in caps below and you are good to go!

composer create-project --prefer-dist SOURCE_SCOPE/SOURCE_NAME="@dev" NEW_PROJECT_NAME --repository '{"type": "path", "url": "/PATH/TO/THE/SOURCE/PROJECT", "options": {"symlink": false}}'

I was recently working on creating some boilerplates for my PHP projects with Composer and wanted to test my install scripts that run after the create-project command. Rather than creating a bunch of releases I just wanted to be able to pull from the local repo as is and then see what happens. Sadly I couldn’t find a simple write up online on how to do this so I had to play with it and hobble what I could find together.

In the end this is what I learned. In the create-project command you have to add the local repo. Although that might seem like enough on the surface you will run into a ‘Could not find package bwd/bwd_theme_base with stability stable.’ error. To get around this you need to set the ‘–prefer-dist’ flag and make sure you set it to ‘@dev’. Then you should be good to go!

The last piece worth mentioning is that Composer will symlink where it can. To avoid this you need to make sure that in the repo declaration you make sure to set the option to not symlink.

Leave a Reply