PHP Shell Execution Reminder

If you are using PHP to execute a custom-written shell script, keep in mind that the $PATH for the web server’s user can be different than the user account you’re using to execute it. Meaning, if it doesn’t behave properly, try using full paths to programs. For example, when writing a shell script to generate thumbnails for JPGs in a directory:

cd $1
for i in `ls | egrep -i '\.jpg$'`; do
    /usr/local/bin/convert $i -thumbnail $2x$3 thumb_$i
done

Just using “convert” rather than “/usr/local/bin/convert” doesn’t work, since /usr/local/bin is not part of $PATH for the web server.

This entry was posted in PHP and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>