22

Is it possible to specify the path to the composer.json file using the cli commands? Even better, is it possible to user a file with a different name?

marcosh
  • 8,780
  • 5
  • 44
  • 74

1 Answers1

23

I would suggest you take a look at this: https://getcomposer.org/doc/03-cli.md#environment-variables

COMPOSER

By setting the COMPOSER env variable it is possible to set the filename of composer.json to something else.

For example:

COMPOSER=composer-other.json php composer.phar install

The generated lock file will use the same name: composer-other.lock in this example.

StuBez
  • 1,346
  • 14
  • 21
sietse85
  • 1,488
  • 1
  • 10
  • 26
  • 1
    what's the windows syntax? using your example command give me `Command "=composer-other.json" is not defined.` – realtebo Nov 19 '20 at 14:46
  • @realtebo Can you try this using GIT Bash for Windows? I don't think the default windows command line supports export variables. – sietse85 Nov 20 '20 at 11:48
  • 1
    @realtebo Windows version of this command would be `set COMPOSER=composer-other.json php composer.phar install` But i see the documentation has an error, the value mus be only the file, so the correct command would be `set COMPOSER=composer-other.json` – Radon8472 Apr 22 '22 at 06:30
  • to truly answer the question ho to specify the path, you should know that you can add a path in COMPOSER-variable to, but you need to specify the vendor dir to, if you try to run a composer install in a sub-directory e.g. like this: `COMPOSER=subdir\composer-other.json && COMPOSER_VENDOR_DIR=subdir\vendor` – Radon8472 Apr 22 '22 at 06:43