GPIO permission denied from web
Closed this issue · 16 comments
Another error, now with GPIO from web.
[Wed Jul 24 17:18:45 2013] [error] [client 192.168.1.102] PHP Warning: file_get_contents(/sys/class/gpio/gpio8/direction): failed to open stream: Permission denied in /usr/share/berryio/includes/functions/gpio.php on line 139, referer: http://192.168.1.106:81/welcome
I'm accessing from another PC on same network (192.168.1.102 is that pc) and raspbery have different IP on same network (106)
Oh, that must be something with permissions from web, because "sudo berryio gpio_status" works from console.
BTW, both API and WEB give me that error from my first comment on this issue
UPDATE: Tried with lynx from raspi console and got same error. So, it's not permissions for outside "world" but also for localhost
Update 2: sorry for so much edits, i forgot to mention that i'm not using port 80 but 81 instead. I folowed readme from instalation and changed both ports file for apache and then berryio file when you need to change port
Thats interesting.
It looks like PHP running under the web server can't read GPIO port 8.
Is it possible you have something else installed which is using SPI and disabling access to the port?
Try switching the direction of GPIO pin 8 back and fourth and see if it clears it.
If it does can you do the following for me... type:
ls -al /sys/devices/virtual/gpio/gpio8
and paste it back in here...
It should look like this:
total 0
drwxrwxr-x 3 root www-data 0 Jul 24 17:25 ./
drwxrwxr-x 13 root www-data 0 Jul 24 17:25 ../
-rw-rw-r-- 1 root www-data 4.0K Jul 24 17:25 active_low
-rw-rw-r-- 1 root www-data 4.0K Jul 24 17:26 direction
-rw-rw-r-- 1 root www-data 4.0K Jul 24 17:25 edge
drwxrwxr-x 2 root www-data 0 Jul 24 17:25 power/
lrwxrwxrwx 1 root www-data 0 Jul 24 17:25 subsystem -> ../../../../class/gpio/
-rw-rw-r-- 1 root www-data 4.0K Jul 24 17:25 uevent
-rw-rw-r-- 1 root www-data 4.0K Jul 24 17:25 value
Thanks..
Daniel
pi@raspberrypi /var/log/berryio $ ls -al /sys/devices/virtual/gpio/gpio8
total 0
drwxr-xr-x 3 root root 0 Jul 24 16:51 .
drwxr-xr-x 14 root root 0 Jul 24 16:51 ..
-rw------- 1 pi pi 4096 Jul 24 16:51 active_low
-rw------- 1 pi pi 4096 Jul 24 17:45 direction
-rw------- 1 pi pi 4096 Jul 24 16:51 edge
drwxr-xr-x 2 root root 0 Jul 24 20:19 power
lrwxrwxrwx 1 root root 0 Jul 24 16:51 subsystem -> ../../../../class/gpio
-rw-r--r-- 1 root root 4096 Jul 24 16:51 uevent
-rw------- 1 pi pi 4096 Jul 24 16:51 value
Oh, and i have instaled Adafruit webIDE, that's on port 80 AFAIK.
Yeah for some reason BerryIO is losing access to that GPIO possibly due to the IDE. Can you try something for me run this command and see if it works, this is how BerryIO changes the permissions...
sudo -u www-data sudo /usr/share/berryio/scripts/gpio_set_device_permissions.sh
I know it looks weird but what we are doing here is the first sudo is so you can pretend you are the web server then the second sudo is the webserver trying to run the GPIO permissions changing script as root. The webserver is limited to only being able to run that particular script as root and a couple of others for security reasons.
If it works then your issue is something else changing the GPIO so its permissions are wrong. You should be able to correct it by changing the pin from no available to in again in the BerryIO web interface.
Tried command and still got same error. I just triend to shutdown all other services (lighthttpd, webiopi and adafruit ide), restarted apache and still having same error. Both witth SPI and GPIO
When you ran the command did you get anything back at the prompt or did it just run OK?
nothing, just successfully run, and command changed permissions
On 7/25/13, Daniel Bull notifications@github.com wrote:
When you ran the command did you get anything back at the prompt or did it
just run OK?
Reply to this email directly or view it on GitHub:
#15 (comment)
If it changed the permissions then isn't the problem solved, have the permissions changed back?
Problem not solved, permissions are now
drwxrwxr-x 3 root www-data 0 Jul 25 11:17 .
drwxrwxr-x 14 root www-data 0 Jul 25 11:17 ..
-rw--w---- 1 pi www-data 4096 Jul 25 11:17 active_low
-rw--w---- 1 pi www-data 4096 Jul 25 11:17 direction
-rw--w---- 1 pi www-data 4096 Jul 25 11:17 edge
drwxrwxr-x 2 root www-data 0 Jul 25 11:17 power
lrwxrwxrwx 1 root www-data 0 Jul 25 11:17 subsystem -> ../../../../class/gpio
-rw-rw-r-- 1 root www-data 4096 Jul 25 11:17 uevent
-rw--w---- 1 pi www-data 4096 Jul 25 11:17 value
Tried restarting apache but still same problem.
When i type command from console (putty) sudo berryio gpio_status i got everything ok, only problem is web when viewing gpio. System stats and everything else works great btw.
Ahhh I think I might know whats going on here...
What user is apache running as?
Can you show me...
ps aux | grep apache
root 2906 0.0 1.5 24344 6892 ? Ss 11:18 0:01 /usr/sbin/apache2 -k start
www-data 2921 0.0 1.4 24616 6300 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2922 0.0 1.4 24616 6352 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2924 0.0 1.0 24416 4796 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2925 0.0 1.4 24616 6504 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2927 0.0 1.3 24616 6220 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2937 0.0 0.9 24376 4132 ? S 11:18 0:00 /usr/sbin/apache2 -k start
www-data 2994 0.0 0.9 24376 4120 ? S 11:28 0:00 /usr/sbin/apache2 -k start
pi 6718 0.0 0.1 3540 808 pts/2 S+ 14:32 0:00 grep --color=auto apache
Oh hold on I spot it...
Look at your permissions...
-rw--w---- 1 pi www-data 4096 Jul 25 11:17 direction
It should be...
-rw-rw---- 1 pi www-data 4096 Jul 25 11:17 direction
Well, your permissions script should do that right ? Or if now, what should i need to type to make it like that ?
Normally it defaults to that, I'm not sure why it wouldn't be like that, kinda strange. I've not heard of this issue from others. The problem is if you change the permissions on these files when you reboot or change the GPIO direction they will reset. If you reboot does it solve the problem?
Nope, tried with reboot at least twice from instaling berryio. Doesn't matter, i will try it on clean install in few days
Yeah please try from fresh and see if you have the same issues. I usually test on a fresh install and I've not seen the problems you are having but it could be that somethings changed. Sorry I couldn't help you.