• Latest News

    Sunday, 10 July 2016

    RaspberryPi handling GPIO input/output using php

    Developing web applications using Raspberry Pi is the cool stuff for every developer and displaying Pi projects over browser makes it more smart if we talk about IoT(Internet of Things).

    Type in cmdline:-

    1. Install apache server: sudo apt-get install apache2 
    2. Install php & dev tools: sudo apt-get install php5 libapache2-mod-php5
    3. Create web application: sudo leafpad /var/www/html/index.php
    4. Remove index.html: sudo rm /var/www/html/index.html

    GPIO setup for php:-

    1. Install GIT: sudo apt-get install git-core
    2. Install WiringPi:
        git clone git://
        cd wiringPi
    3. Check wiringPi:
         gpio mode 1 out  
         gpio write 1 1
         gpio readall

    GPIO WiringPi HeaderPins:-

    PHP Code:-

    1. Create form using GET or POST method & call same php file
    2. Read form using conditionals & run GPIO using exec() function or shell_exec() function.

    Create Form: index.php

    <form method="POST" action="index.php">
       <input type="submit" name="start" value="start">
       <input type="submit" name="start" value="start">

    GPIO setmode: system("gpio mode 1 out")

    system("gpio mode 1 out");
      exec("gpio write 1 1");
    else if(isset($_POST['stop']))
      exec("gpio write 1 0");

    GPIO read: exec("gpio read 1",$status)

    system("gpio mode 1 out");
      exec("gpio read 1",$status);
       echo "SENSE"
       echo "NO SENSE"


    3. Running python script in background using shell_exec() function.
    It needs various permissions which you have to configure manually, read here

    Read more:
    For more php codes comment!
    • Blogger Comments
    • Facebook Comments


    Post a Comment

    Thanks for your comment. We will try to reply as soon as possible.

    VSL Creations

    Item Reviewed: RaspberryPi handling GPIO input/output using php Rating: 5 Reviewed By: Vishal Aditya
    Scroll to Top