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)
If you want to set it only in specific circumstances, you can do:
exec("PATH=/my/path ./bin");
The way to alter the PATH used by apache on Mac OS X is described here: http://lists.apple.com/archives/macos-x-server/2008/Sep/msg00433.html
As stated in that post:
[A]dd the following text into [the file
/System/Library/LaunchDaemons/org.apache.httpd.plist
] at the fifth line:<key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin</ string> </dict>
See the man page for
launchd.plist(5)
for details on the syntax I'm using here.If you need to run your PHP commands as CLI sessions, you'll also probably need to add
/opt/local/bin
as a new path under/etc/paths.d
work. For instance, something like this:shell> sudo echo "/opt/local/bin" >> /etc/paths.d/macports
See the man page for
path_helper(8)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With