I try to execute a command from PHP using Symfony's Process
but I can't get it to work because PHP refuses to find the executable.
Example with npm:
use Symfony\Component\Process\ExecutableFinder;
var_dump((new ExecutableFinder)->find('npm')); // returns null
$process = new Process(['npm', '--version']); // also tried /usr/bin/npm here
$process->run();
var_dump($process->getOutput()); // returns empty string
PHP should look up in the following paths:
echo getenv('PATH'); // /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
I created a symlink in /usr/bin
as it is in PHP's PATH
:
$ cd /usr/bin && ll
...
lrwxrwxrwx 1 root root 40 Aug 18 14:03 npm -> /root/.nvm/versions/node/v14.6.0/bin/npm*
...
The npm
executable is in PATH
:
$ whereis npm
npm: /usr/bin/npm /root/.nvm/versions/node/v14.6.0/bin/npm ...
Still, PHP refuses to find the executable. It also says:
var_dump(is_executable('/usr/bin/npm')); // returns false
exec('/usr/bin/npm --version', $output, $errno); // $errno is 126
I'm using Ubuntu 18.04 on WSL, tried restarting apache, modifying permissions chown www-data:www-data npm
of the symlink, creating symlinks in every other path /usr/local/bin
etc., ... nothing works. I'm pretty much lost right now.
Thank you for your help!