views:

56

answers:

3

Hi.

I am currently working on my own little project, but I have a little problem: I want to set the $PATH environment variable to ./bin, so that when I use exec() and similar functions, it would only search for binary files in that directory (unless I explicitly tell it otherwise).

I have already tried putenv(), which won't work unless I have safe-mode enabled, which I'd prefer not to; and I also tried apache_setenv(), but that didn't seem to work either.

Are there any other solutions I might want to try?

(I am using a Linux machine with PHP 5.3.2)

+1  A: 

instead of setting the path to bin and calling foo, why don't you just explicitly invoke bin/foo?

sreservoir
A: 

If You have path set for Yours user AND if Your scripts run as Yours user, only thing You should do, is to set up this path for Yours shell, but is Your's scripts run as ie. apache user (www-data in debian-like systems) for this to work, You should set this PATH for that user explicte

canni
The problem is that I do not want it to apply everywhere on the server, only in **one** PHP script...
Frxstrem
Than, You cannot do that without disabling safe-mode (as my knowledge says, but i may be wrong), PATH is a shell-oriented environment variable, not a script-oriented
canni
+2  A: 

If you want to set it only in specific circumstances, you can do:

exec("PATH=/my/path ./bin");
Artefacto
Thanks, why didn't I think of that? :P
Frxstrem
that PATH setting is kind of pointless since you're also giving an actual relative path.
sreservoir
@sreservoir No it's not. The path doesn't affect only the resolution of `./bin` (in this case it doesn't affect it at all, since it's a relative path). If `./bin` is e.g. a script that calls other applications it can affect the path resolution for them.
Artefacto