So I have a PHP script that is using wget
to download some images. It looks something like this:
exec('wget -O saveImage.png http://location.of.image');
When I run my script on a different machine, it works. However, when I run it locally, it doesn't work. I think this has to do with how I installed wget
. Locally, I am running Mac OS X 10.6 Snow Leopard and installed wget
using Homebrew. So when I run which wget
(as me) the location of wget
is /usr/local/bin/wget
(which is a symlink to the Homebrew Cellar). I have determined that the user that is running the script is called daemon
. I know that the wget
script is owned by the staff
group and I don't think that the daemon
user is part of that group (but I don't know how to check). Anyway, I don't think that the daemon
user has permission to execute the command and/or can't find the script. What should I do?
Update: So I was able to run the script when I specified the exact location:
exec('/usr/local/bin/wget ...etc');
This makes me think it's not a permissions issue, but rather a "unable to find wget" issue. I don't think I can specify the exact location since it is different on the various machines that this script runs on. So what should I do to get around this issue?
Solution:
By adding /usr/local/bin
to the environment $PATH
variable, PHP was able to find wget. Here's how I did it in PHP:
//help PHP find wget since it may be in /usr/local/bin
putenv('PATH=' . getenv('PATH') . PATH_SEPARATOR . '/usr/local/bin');
if (exec('which wget') == null) {
throw new Exception('Could not find wget, so image could not be downloaded.');
}
//now we know wget is available, so download the image
exec('wget ...');