herd-community icon indicating copy to clipboard operation
herd-community copied to clipboard

[Bug]: $PATH used in context of request is different from the context of terminal or tinker

Open mohammed-adil-moughal opened this issue 1 year ago • 7 comments

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

mohammed-adil-moughal avatar Mar 07 '24 07:03 mohammed-adil-moughal

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:.

laserhybiz avatar May 05 '24 12:05 laserhybiz

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? 😅

sschlein avatar May 13 '24 12:05 sschlein

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 avatar May 13 '24 13:05 laserhybiz

@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 avatar May 14 '24 08:05 mpociot

@mpociot I use the gs command

laserhybiz avatar May 14 '24 08:05 laserhybiz

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

laserhybiz avatar May 14 '24 08:05 laserhybiz

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

stefket avatar May 16 '24 15:05 stefket

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 avatar Jun 03 '24 09:06 mpociot

@mpociot Is it possible that changes to the 8.X-fpm.conf files are sporadically overwritten by Herd?

stefket avatar Aug 13 '24 07:08 stefket