"install"]; # only for install without anything // $command = ['command' => 'require', 'packages' => ['maatwebsite/excel:~2.1.0']]; # for install a specific package // $command = ['command' => 'remove', 'packages' => ['maatwebsite/excel:~2.1.0']]; # for remove a specific package // define directory for extract define('EXTRACT_DIRECTORY', "/your/desired/directory"); //Use the Composer classes use Composer\Console\Application; use Composer\Command\UpdateCommand; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Output\BufferedOutput; $composerPhar = new Phar(EXTRACT_DIRECTORY . "/composer.phar"); // you must use it with null and true parameters if you wish to call manytimes this file $composerPhar->extractTo(EXTRACT_DIRECTORY, null, true); putenv('COMPOSER_HOME=' . EXTRACT_DIRECTORY . '/bin/composer'); //This requires the phar to have been extracted successfully. require_once (EXTRACT_DIRECTORY . '/vendor/autoload.php'); // goto extract directory chdir(EXTRACT_DIRECTORY); // increase memory limit (needed if you run in an environment with less than 256MB but you have up to 256MB) ini_set("memory_limit", "256M"); //Create the commands $input = new ArrayInput($command); $input->setInteractive(false); //Create the application $application = new Application(); // avoid calling exit; $application->setAutoExit(false); echo "
"; // start buffering. // some other codes invokes StreamOutput or ConsoleOutput but // at the end, composer uses "echo 1> /dev/null what causes buffer get empty before to be used as html output $output = new BufferedOutput(); $application->run($input, $output); $stream_output = $output->fetch();// get buffer string echo $stream_output; echo "