Execute code to switch light on with PHP
I solved it.The answer was easy, indeed the user "http" was not allowed to execute things from the wiringpi library which the C-program needed to run.
In the end I simply did:
chmod +s action
(This sets modifies the executable (called "action") to always run with root privileges.)...and the code ran as expected with the following PHP file (index.php):
<?phpsystem('action 63 A off');?>
Thanks for all the help!
is the C program a binary that you can pass parameters to? If so the following should work.
string exec ( string $command [, array &$output [, int &$return_var ]] )
for example
exec("controller.exe {$data}",$output);
data being parameters to pass into the executable, and output being any response from the executable.
See here for an example
Considering echo exec('action')
is working but not exec('action 63 A off')
, it is seeming that the command is failing if there parameters .
If that is the case , why not make two shell scripts / batch files one for On
and one for Off
, and call those from PHP ?
File switch_on
contents :
action 63 A on
File switch_off
contents :
action 63 A off
Make sure switch_on
and switch_off
files are accessible by PHP and have Execute permission .
switch_on.php
<?php exec('switch_on');?>
switch_off.php
<?php exec('switch_off');?>