4

I have been attempting to use RaspiStill in PHP for a number of days now. I have searched around and have been unable to come up with a solution.

I have been attempting to use shell_exec() in my php file like so:

shell_exec("/usr/bin/raspistill -rot 180 -q 70 -w 1920 -h 1080  -o /media/64GB/www/timelapse/image_image.jpg 2>&1")

Which works if you use it from the console and type:

php php_script.php

At first I was getting this error when running the php script in the browser:

sudo: no tty present and no askpass program specified

This was resolved by updating /etc/sudoers with:

Defaults:www-data !requiretty

I also added this line:

www-data ALL=(ALL) NOPASSWD: ALL

No error is returned in the apache logs so I am not sure what else to try.

  • What else is in your PHP script? The shell_exec command shown doesn't use sudo, so I don't see how the sudo error you received is related to that command. – HeatfanJohn Oct 13 '13 at 13:31
  • was this ever resolved? I'm encountering the same issue and have tried every suggestion but to no avail. – Emanegux May 3 '16 at 3:05
3

If you find your apache web service is unable to run the raspistill command you may need to modify the www-data apache user to allow it to run the command:

echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules

and this one

usermod -a -G video www-data
1

Try adding the "-n" param to your raspistill command to disable previews, see if that helps. You may also try "-t 0" to reduce wait time.

  • That didn't help either – jason Oct 14 '13 at 1:05
0

Found a tutorial for something similar that helped me: http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=56209&hilit=+php

The part that helped me in particular was:
sudo chmod 777 /var/www
sudo chmod 777 /dev/vchiq

after entering those commands Shell_exec would successfully invoke raspistill.

0

I was able to get it working by using the following:

sudo chmod 777 /dev/vchiq

and

usermod -a -G video www-data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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