Executing shell commands


Just a quick post - if you’re using PHP’s shell_exec to execute shell commands, take note of the following:

Permissions
If you’re reading or writing files, ensure that your working directory has the correct permissions for the www/apache user to access what it needs. On some systems, PHP will run as the nobody user, so adjust accordingly.

Pipes
Using pipes and redirection inside your command string is not going to work most of the time, what you probably want to do is create a seperate bash script on your server that contains all the commands you want to run. Then use PHP to execute the single bash script.

Paths
This one has got me a few times - just because a command is in the path when you’re SSH’d into the server, it doesn’t mean that it’ll be on PHP’s perceived path. This means that you’ll need to specify the full path to any system applications you are using (not for standard commands like cat, though). For example:

   shell_exec("/usr/local/bin/htmldoc --jpeg=0 --webpage \\
      -f out.pdf in.html");
Share this post
  • Digg
  • StumbleUpon
  • Reddit
  • del.icio.us
  • Facebook
  • muti
  • Mixx
  • Google
  • laaik.it

This entry was posted on Tuesday, March 6th, 2007 at 11:54 am and is filed under MySQL. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Executing shell commands”

  1. Nikole Timmel said this on

    Skip Hop Studio Diaper Tote Tote is awesome.So a lot of wallets - and not really these modest, worthless pockets, either. Almost all of the storage compartments are a fantastic dimension and genuinely assist keep every thing organized. The handles are a great length and fit nicely more than the actual shoulder; the handle straps additionally stay put on my own arm, which is actually critical as soon as you’re holding a infant. The bag looks excellent, as well. Not too fancy, but not too casual. (I’ve it in black) The material is soft (can’t feel of a superior word) so it’s effortless to squeeze in to tight spaces - but yet it’s sturdy. I’ve a Fleurville Lexi tote and I adore it, too, but this tote is type of rigid. I consider this Skip*Hop may turn out to be my everyday bag. It is a little bit substantial - so if you are not really in to large bags this may perhaps be greater as an over-night diaper bag.

Leave a Reply