#include <string>
#include <getopt.h>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <unistd.h>
#include <wiringPi.h>

using namespace std;

void light_1_on() {
  digitalWrite(0, HIGH);

int main( int argc, char ** argv){

  cout << "Setting up wiringPi" << endl;
  pinMode(0, OUTPUT);



Built using: g++ on.cpp -o on -lwiringPi

Permissions changed with: chmod 777 on

Access changed with: chown www-data:www-data on

When run ./on via the terminal, the light that's connected to this GPIO output turns on. But when run via my exec or shell_exec via php, the light does not turn on.

Any ideas why I might not be able to turn the light on via execution in php? Any fixes or workarounds for this?



It turns out I had to add gpio to the group for www-data. I had to use this:

sudo usermod -a -G gpio www-data

Took me quite a while to figure this out. Hope it helps someone!

| improve this answer | |

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.