David Rekowski's random stuff

Nested composer configurations


This article describes how multiple composer.json configurations files can be used to build a nested structure in a project which allows for deviating configurations, e.g. to use different versions of dependencies or combine a number of standalone modules. You will need the main project (master) and any number of standalone sub projects.


PHP, composer, nesting, configuration, composer.json


This is simply a proof of concept. Follow this approach at your own peril. I have not investigated security aspects. There may be a more appropriate solution to this specific problem.


You will have multiple versions of dependencies installed, which may take up a more or less significant amount of disk space.


Basically, all you need to do is to trigger the composer update/install commands of your sub projects from the master project.

Required changes

composer.json (excerpt)

"scripts": {
	"post-install-cmd": [
		"cd ./sub-project-folder/ && composer install --no-dev && cd -"
	"post-update-cmd": [
		"cd ./sub-project-folder/ && composer update && cd -"

It may be you have or want to use a local composer script instead of a globally installed one. That being the case, you need to change composer to the relative path to the composer installation you want to use, e.g. ../composer.phar.

You may want to put the commands into a separate script, but for simplicity's sake, it is inline here.

Notes on automated builds

If the subsequent composer call does not work in a build setting (e.g. jenkins), it may be required to pass a whitelist parameter:

php -d 'suhosin.executor.include.whitelist=phar' composer install --no-dev