0

I'm trying to running an PHP code from a URL so when the URL is opened the script must to run at server (Nginx).

URL example: https://my-server.com/deploy.php

I have 3 code blocks inside this script:

  1. git pull (works fine);
  2. rm -rf vendor (works fine);
  3. composer install (not worked);

Trying to debug, I change this part of code to:

$composer = shell_exec('composer install 2>&1');
echo "$composer";

Note: before use shell_exec I try with passthru and this didn't work too.

So I got this error:

sh: 1: composer: not found

And another time this error:

[RuntimeException]
The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly

If a run the same file by SSH command, like:

php deploy.php

The code works fine and execute the composer install.

At first I thought could be the file permission, so I change to 777 and the error keeps happen.

Why the composer command didn't work when is called by URL? Anyone knows how to fix this?

4
  • PATH and HOME will differ for the Apache-run PHP setup.
    – mario
    Aug 13, 2020 at 23:24
  • Do you know how find the PATH e HOME values in Nginx Server? Aug 13, 2020 at 23:29
  • Probably /etc/default/nginx, or perhaps PHPs fpm pool config env[PATH]?
    – mario
    Aug 13, 2020 at 23:44
  • I got at composer documentation, in my case was /home/<user>/.composer. Aug 13, 2020 at 23:46

1 Answer 1

0

I resolve this, like Mario sad in comments adding the COMPOSER_HOME value.

So my code do like this:

$composer = shell_exec('
    export COMPOSER_HOME=/home/[user]/.composer;
    composer install 2>&1'
);
echo "$composer";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.