/var/www/html/index.php
<?php
exec("./on");
shell_exec("/var/www/html/on");
on.cpp
#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;
wiringPiSetup();
pinMode(0, OUTPUT);
light_1_on();
}
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?
Thanks!