-1

This post is in relation with this : Run composer with a PHP script in browser

My problem is to solve how to install a library without terminal and take in consideration some hosting do not accept the exec command.

In summary the user can just click on the button to install apps with the library

Thank you.

I tried 2 solutions :

  use Composer\Console\Application;
  use Symfony\Component\Console\Input\ArrayInput;
  use Symfony\Component\Console\Output\StreamOutput;



  putenv('COMPOSER_HOME=' . self::$root); // /www/mywebsite/shop/
  putenv('COMPOSER_CACHE_DIR=' . CORE::BASE_DIRECTORY . '/Work/Cache/Composer/');
  putenv('COMPOSER_HTACCESS_PROTECT=0');

first with this code

 $stream = fopen('php://temp', 'w+');
      $output = new StreamOutput($stream);
      $application = new Application();
      $application->setAutoExit(false);
      $code = $application->run(new ArrayInput(array('command' => 'install tinify/tinify')), $output);
      $result = stream_get_contents($stream);

      var_dump($code);
      var_dump($result);

The result is : (not work and nothing is installed)

int(1) string(0) ""

The second approach :

  $input = new ArrayInput(array('command' => 'install tinify/tinify'));
  $application = new Application();
  $application->setAutoExit(false); // prevent `$application->run` method from exitting the script
  $result = $application->run($input);

  var_dump($result);

The result is : (not work and nothing is installed)

 int(1) 
Michael
  • 19
  • 3
  • Possible duplicate of [Run composer with a PHP script in browser](https://stackoverflow.com/questions/17219436/run-composer-with-a-php-script-in-browser) – fonini Oct 16 '19 at 17:20
  • @fonini Do you look my first sentence, it's not a duplicate. run composer in browser is the link with Run composer with a PHP script in browser – Michael Oct 16 '19 at 17:26
  • I belive you won't be able to run any command without exec. – fonini Oct 16 '19 at 17:28

1 Answers1

-1

You do not need to run composer on the production server.

You can run composer in a project on a computer with similar software (OS, php version). Then you can copy already built project directory with vendor folder in it to the production server.

Usually you can zip/gzip it first then transfer then unzip/ungzip. For the follow up updates something like rsync may be a fast solution for updating only those parts of project folder that changed.

You may want to have a script that copies your development directory first then cleans up any personal credentials (e.g. passwords to any SaaS solutions you use for development), and then does the composer & transfer automatically.

przemo_li
  • 3,932
  • 4
  • 35
  • 60