[Bug]: $PATH used in context of request is different from the context of terminal or tinker
Operating system version
macOS sonoma 14.3.1
System architecture
ARM64 (M1, M2, etc)
Herd Version
1.4.1
PHP Version
php 8.2.16
Bug description
When running exec while in the context of a request, the $PATH variable is different from the terminal and tinker. And there's no way to update that to be similar to what is used in the terminal or tinker.
Also, similar possibly related issue when installing node js via HERD and then installing a node package globally, that package is not located within the context of the request in HERD
Steps to reproduce
To reproduce
1 echo $PATH in terminal
2 exec("echo $PATH") in php artisan tinker
3 exec("echo $PATH") from a request from the app ie an api call
1 and 2 are the same and correct but 3 is different
Relevant log output
No response
I have the same issue, when I echo the $PATH from a web request it returns /usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.
The problem is that the php-fpm process is not running in a sourced shell – usually the PATH is only available in interactive shells and not for processes. This is also common for normal web servers and setups that you have in Laravel Forge, etc. and so I am not sure that this is actually a bug but preventing you from doing something weird that won't work on a remote server anyway? 😅
I am trying to run a simple command using laravel's Process facade, I don't have this issue when I use php from brew, neither do I have the issue in forge
@laserhybiz which binary exactly are you trying to execute? I just re-installed Laravel Valet (which uses PHP from brew) and I am unable to run a binary that is inside my PATH, like this:
\Illuminate\Support\Facades\Process::run('ffmpeg');
I also don't see any configuration in either brew or valet that would allow this.
@mpociot I use the gs command
I'm also having issues using spatie browsershot
The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=npm root -g node '......' failed
I had the same problem. I solved it by editing the php-fpm config file under ~/Library/Application Support/Herd/config/fpm/8.X-fpm.conf and adding the following line under [herd]:
env[PATH] = /usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin
I'm closing this, as I don't think this is an issue in Herd itself as valet behaves in the same way.
If you want to use binaries without specifying the absolute paths, you should adjust your FPM configuration file as mentioned by @stefket
@mpociot Is it possible that changes to the 8.X-fpm.conf files are sporadically overwritten by Herd?