Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 ...');
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Half an answer...

Make sure that wget is in your default PATH environment variable for the user you run the script with (on each machine). Looking at the output of exec('echo $PATH') might be a good way to do this. The result has to be like ...:/usr/local/bin:....

Dunno how to change the default PATH value on OSX though.

share|improve this answer
1  
Also remember that certain non-interactive environments - like cronjobs behave differently for security reasons, and may have different, or empty environment settings, particularly with respect to the PATH in order to prevent something malicious from being placed in the path and being automatically run. –  Stephanie Jul 23 '11 at 0:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.