Question

On my Raspberry Pi Model B-Rev2 running Raspbian 3.10.25 I following the instructions on https://github.com/ronanguilloux/php-gpio to control the pins. But I simple cannot get it to work. According to instructions this should be the command in triggerMyScript.php:

exec('sudo -t /usr/bin/php ./myGpioScript');

But depending on content in myGpioScript I get errors in Apache log error.log saying stuff like command not found and No such file or directory.

I have also made additions to /etc/sudoers as instructed.

It works perfectly fine if I run php triggerMyScript.php from the command line.

Was it helpful?

Solution

After spending several hours I found the solution. I needed to do the following things beside what the instructions on php-gpio says:

  • in myGpioScript the first line had to be #!/usr/bin/php instead of #!/usr/bin/env php
  • I had to add php after -t, like this: exec('sudo -t php /usr/bin/php ./myGpioScript'); (which makes sense when you think about it, but instructions doesn't say it like that)
  • I had to add this to the sudoers file: www-data ALL=NOPASSWD: /usr/bin/php - so that www-data can also run php without limitations. Specifying permission for the actual script files was actually not necessary!

File permissions on any of the files are not relevant either, so just leave them low.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top