6

Trying to execute it with all possible params, such as -d and full path etc.. No errors. When running another commands, all is ok, when running composer from CMD, all is ok too. Have tried exec, system, shell_exec etc.. What it could be?

echo system('php composer.phar install');

andymcgregor
  • 1,005
  • 2
  • 13
  • 28

2 Answers2

13

Try outputting the error stream as well:

system('php composer.phar install 2>&1');

It might give you more of a hint as to what is going wrong.

Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
StampyCode
  • 7,218
  • 3
  • 28
  • 44
  • (assuming you are running on Linux) – StampyCode May 18 '13 at 16:02
  • Thanks, got error now - It said that env.variable "APPDATA" is undefined. I set it manually, with putenv(), and then got it running! But why it's undefined? Running on Windows. – andymcgregor May 18 '13 at 16:41
  • 2
    Got it, when composer runs from php script, not from cmd, it does not import environment variables such as PATH etc.. For this purpose, we need to do it manually, for example PATH variable are stored in $_SERVER, and it could be imported from it by putenv('PATH=' . $_SERVER['PATH']) :) – andymcgregor May 20 '13 at 09:50
  • 3
    If you got error "The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly" put putenv("COMPOSER_HOME=/absolute/path/to/composer.phar/directory"); before calling system() – ymakux May 31 '17 at 20:25
  • @ymakux you saved me! It works perfectly, thank you! – fractalbit Nov 11 '20 at 21:24
1

Try this

$path = 'path where, composer.phar and composer.json exists';

var_dump(shell_exec("
  cd $path;
  export COMPOSER_HOME=$path./.config/composer;
  php $path/composer.phar show -i 2>&1"));

Tested on Linux.

bareMetal
  • 425
  • 1
  • 7
  • 20