fableman
Posts: 22
Joined: Mon Oct 22, 2012 12:27 pm

www-data /sys/class/gpio/gpio19/value: Permission denied

Fri Sep 18, 2015 4:09 pm

Hi

I read everything there is to read about making www-data able to access GPIO pins.
Nothing work anymore (worked on my old raspberry build 1 year ago, something changed)

I try to make my php script from a webpage to run a batch script that access a GPIO pin
I can't get it to work as www-data , only as root! :(

I set all my gpio's as user root when PI reboots.

my php script access myprogram

myprogram do this: echo 1 > /sys/class/gpio/gpio19/value

cat /var/log/apache2/error.log
/var/www/myprogram /sys/class/gpio/gpio19/value: Permission denied

(I tried to use sudo,visudo chmod 777,chown ..... about anything there is to try!!!)

I really need some help before I start pulling my hair :)
/Cheers...

User avatar
joan
Posts: 14079
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Fri Sep 18, 2015 4:51 pm

You should be able to use the GPIOs if the user is a member of the gpio group.

Unfortunately the permissions of the exported GPIO is wrong with the latest kernels. It is set owner/group root/root, I think it should be root/gpio.

User avatar
DougieLawson
Posts: 35542
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Fri Sep 18, 2015 9:26 pm

sudo useradd -g www-data gpio
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
joan
Posts: 14079
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Fri Sep 18, 2015 9:29 pm

DougieLawson wrote:sudo useradd -g www-data gpio
Unfortunately that's not enough at the moment. The exported GPIOs are owner root, group root.

User avatar
DougieLawson
Posts: 35542
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Fri Sep 18, 2015 9:30 pm

joan wrote:
DougieLawson wrote:sudo useradd -g www-data gpio
Unfortunately that's not enough at the moment. The exported GPIOs are owner root, group root.
Ah, yes. I've just remembered there's that bug in the latest 4.1.xx kernels.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Sat Sep 19, 2015 1:31 am

It is not a kernel bug. The true device path has changed at least twice, and varies by platform, including between Pi1 and Pi2 I assume. This is clearly intentional. It causes no problems for the user because the documented interface is via the symlinks in /sys/class/gpio/.

It is a bug in the existing udev rule that it ignores the device path—which udev knows—and instead hard codes various guesses. I believe it should also use RUN, rather than PROGRAM:

Code: Select all

KERNEL=="gpio*", RUN="/bin/sh -c 'chgrp -R gpio /sys/%p /sys/class/gpio && chmod -R g+w /sys/%p /sys/class/gpio'"
(This is still pretty ugly. Essentially it changes the permissions on "export" when detecting "gpiochip0". I do not understand why that is necessary, since "udevadm test /class/gpio" suggests that it should trigger fine by itself. Also, is there really no way to get GROUP and MODE to apply to the files in a directory, without an external helper?)

I am not sure who maintains the udev rule. In the Foundation's wheezy repository, it is provided by packages python{3,}-pifacecommon. In jessie it appears to be gone.

fableman
Posts: 22
Joined: Mon Oct 22, 2012 12:27 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Sat Sep 19, 2015 11:45 am

Sounds like all I can do, is to wait and hope it get fixed in the next release..

Guess I have a make a perl API running as root that will check for a web request to handle my GPIO's :(

fableman
Posts: 22
Joined: Mon Oct 22, 2012 12:27 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Wed Oct 07, 2015 6:00 pm

Anyone got any news regarding this topic?

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Wed Oct 07, 2015 7:48 pm

fableman wrote:Anyone got any news regarding this topic?
The issue is fixed, in a way, in the Foundation's new jessie image.

If you want to run a new kernel on a wheezy image, or upgrade to jessie manually, try adding the line of code from my post above to a new file /etc/udev/rules.d/99-gpio.rules

Remember to add user www-data to group gpio

rpiuser2016
Posts: 75
Joined: Tue Jan 12, 2016 1:53 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Thu Mar 28, 2019 12:40 pm

Hi!
I have execute

Code: Select all

sudo useradd -g www-data gpio
but it gives me an error:
useradd: user «gpio» already exicted
And I can not control GPIO as a www-data:
./water_off.sh: line 6: /sys/class/gpio/export: Permission denied
./water_off.sh: line 7: /sys/class/gpio/gpio19/direction: Permission denied
Help please

User avatar
rpdom
Posts: 14742
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Thu Mar 28, 2019 12:43 pm

rpiuser2016 wrote:
Thu Mar 28, 2019 12:40 pm
Hi!
I have execute

Code: Select all

sudo useradd -g www-data gpio
but it gives me an error:
useradd: user «gpio» already exicted
It will. You are trying to create a user called gpio with access to the www-data group, but you really want to add the www-data user to the gpio group. Also, you don't want to use useradd. That tries to create a new user. What you want is:

Code: Select all

sudo usermod -G gpio www-data

rpiuser2016
Posts: 75
Joined: Tue Jan 12, 2016 1:53 pm

Re: www-data /sys/class/gpio/gpio19/value: Permission denied

Thu Mar 28, 2019 1:15 pm

Thanks for your fast reply!

Code: Select all

sudo usermod -G gpio www-data
This works! Now I am changing to www-data user and can execute this scripts, them works! But I am still cannot start them using RPi-CAM Webinterface buttons:

viewtopic.php?f=43&t=63276&p=1448295#p1448295

Return to “Advanced users”