I have apache2, php5 installed. I'm trying to execute the next code in my php script

shell_exec('/usr/bin/omxplayer -o hdmi "'.$file_name.'" < omfifo &');
shell_exec('echo -n . > omfifo');

$file_name is a file and it does exist in /var/www directory. www-data user is in sudoers file. /var/www/ is 0777. generally shell_exec does work I checked it with this code

shell_exec('sh boo.sh');


echo "Download finished" | wall;

When I execute the code with omxplayer in just a console it works fine. I can also launch omxplayer from php without using pipes, but I do need them.

  • have you solves this? i have the same problem..
    – Marc Ster
    Commented Feb 26, 2014 at 20:36

1 Answer 1


OK, I had the same problems, so here were the things which helped me:

  1. Go to /etc/apache2, and in the file envvars, change login, and user group to pi, or the user you are using. (P.S. This thing is really bad for website security, if you plan to publish the website, you will need to play around with user groups!). By doing that you are changing the user apache uses to execute code.
  2. Change every function to it's full name (ls --> /bin/ls, using sudo: /usr/bin/sudo, you can find this information by writing in the terminal whereis sudo)
  3. Use \ in front of special characters in Php, so:

    echo('Hello - **'Max'** ');

    should be:

    echo('Hello **\'Max\'** ');
  4. Check your apache error log. It is located in /var/log/apache2/error.log. In that file there is every error Php has encountered.

So, I hope that does it. If it did not, I suggest removing variables in your code, and trying to pinpoint the bug. By the way, omxplayer can take a long time to load, so be sure to wait 1-2 minutes before quitting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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