Skip to main content
Commonmark migration
Source Link

###Please note

Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

###Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

replaced http://raspberrypi.stackexchange.com/ with https://raspberrypi.stackexchange.com/
Source Link

###Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their commentcomment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

###Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

###Please note

This is a very quick answer (a work in progress if you will), as I have not had time to test it, and it is way past my bed time. I will tidy up this answer tomorrow, once I have time to run it myself.

However...

I think (I may be wrong) that you are missing an export to expose the GPIO pins to PHP. You may need to do

gpio export 29

Thus, your script will become

<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>

Try that.

I have just found a thread on the Pi forums, PHP GPIO Library, that says the same thing, so maybe I am correct. There are some other interesting points raised in that thread, which you may find useful.

However, the export command is not included in many other examples/tutorials, so maybe it is not the way forward. For example, from PHP on Raspberry Pi, this HTML/PHP script does not include the export:

<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>

Note: As PandaLion98 says in their comment, getting scripts to run in Apache can be dangerous, if they are publicly facing.

added 62 characters in body
Source Link
Jacobm001
  • 11.9k
  • 7
  • 47
  • 57
<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>
<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>
<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>
<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>
<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>
<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>
<?php 
system("gpio export 29");
system("gpio -g mode 29 out");
system("gpio -g write 29 1");
?>
<html>
 <head>
 <meta name="viewport" content="width=device-width" />
 <title>LED Control</title>
 </head>

 <body>
  LED Control:
  <form method="get" action="gpio.php">
        <input type="submit" value="ON" name="on">
        <input type="submit" value="OFF" name="off">
  </form>
  <?php
    $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
    if(isset($_GET['on'])){
        $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
        echo "LED is on";
    }
    else if(isset($_GET['off'])){
        $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
        echo "LED is off";
    }
  ?>
 </body>
</html>
Added link to thread.and another example
Source Link
Greenonline
  • 2.8k
  • 5
  • 24
  • 36
Loading
Added link to thread.
Source Link
Greenonline
  • 2.8k
  • 5
  • 24
  • 36
Loading
Source Link
Greenonline
  • 2.8k
  • 5
  • 24
  • 36
Loading