Bash script though webpage to take picture
So I'm trying to run a bash script through a webpage using PHP, (on a raspberry pi if thats relevant). Ordinary commands work fine like 'ls' etc. However when trying to take a picture from the webcam connected to the Pi , using the command: 'fswebcam image.jpg' it doesn't work at all.
I'm struggling to determine the issue. could it be something to do with permissions?
Taking a picture directly through the terminal works fine.
EDIT:
Sorry about not including this info in the beginning but I'm quite novice at all things web... But I'm using a LEMP stack so I don't have Apache running but using Nginx
As you suspected, I think also that you are facing permission issue with your hardware on raspberry Pi. As the subject mix raspberry / hardware / linux / web, you read many crap solutions on internet; they often deliver root permission everywhere!
In your case I think that your apache log file ( /var/log/apache2/error.log
?) will contain the error message, kind of:
can not access /dev/vchiq
For the moment your apache user (www-data) can not access it:
pi$ ls -l /dev/vchiq
crw-rw---T 1 root video 248, 0 Jan 1 1970 /dev/vchiq
Type those commands:
sudo usermod -a -G video www-data
sudo /etc/init.d/apache2 restart
It means that the user www-data will be added in group video (that has access to /dev/vchiq). Then you have to restart your apache server so that it rereads the group file and get informed of the change. Note: you would add www-data to gpio group, if you had to access them from web.
PHP runs with apache user permissions.
Does your apache user have permissions to start fswebcam?
ll $(which fswebcam)
So from the error message I received (posted above) I realised that /dev/video0 needed permissions for other users. so my solution was to just go:
chmod 777 /dev/video0
It's probably quite a dirty solution but works nonetheless
链接地址: http://www.djcxy.com/p/77158.html下一篇: Bash脚本通过网页拍照