0

I am trying to get the status of gpio17 via php like that:

(Installed: Raspbian, Apache2, PHP5) This is what i do:

echo "17" > /sys/class/gpio/export

echo "out" > /sys/class/gpio/gpio17/direction

echo "1" > /sys/class/gpio/gpio17/value

After setting the gpio i call the 'gpio_test.php' file in the browser. This is the gpio_test.php file:

<?php
trim(@shell_exec("cat /sys/class/gpio/gpio17/value"));  
?>

When I look into my apache2 log file it says:

"cat /sys/class/gpio/gpio17/value permission denied"

What can I do to fix this?

  • You need root access to access the gpios. You either have to use sudo (not advisable for a webserver) or change the permissions. See e.g. raspberrypi.org/forum/viewtopic.php?f=44&t=8999 – Gerben Feb 6 '14 at 20:11
  • hm didn't work.. – Marc Ster Feb 6 '14 at 20:52
  • How are you exporting the gpio17? – Milliways Feb 7 '14 at 1:14
  • Have a look at the post again, i have updated it – Marc Ster Feb 7 '14 at 7:26
  • It is simpler to use /usr/local/bin/gpio export 17 out but the code you have listed should do the same. I can't see why it doesn't work. It would be interesting to see the result of ls -la /sys/class/gpio/gpio17/ – Milliways Feb 7 '14 at 11:52
1

The output you posted explains why it is not working. edge and value are both owned by root

If you run /usr/local/bin/gpio export 17 out they should be owned by your user (probably pi). NOTE do not run as sudo

I am not sure if /usr/local/bin/gpio normally has SUID permission, but if not you can set it with

sudo chmod u+s /usr/local/bin/gpio

  • Thank you. I have installed raspbian again and used wiringpi which works fine. But your answer is correct :) – Marc Ster Feb 8 '14 at 8:47

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.