Raspberry Pi. Install SdCard. VNC. Apache. PHP. Turn LED on/off. Pushbutton

Hello friends,

this topic is about

  • installing Raspberry Pi on an SdCard.
  • Remote desktop with VNC.
  • Installing Apache with PHP.
  • Wiring Pi to control the pins of the Raspberry.
  • Turn on/off an LED from a web page and from App Inventor.
  • Check the state of a button from App Inventor.

I used Raspberry Pi 3 Model B and SdCard 32 GB

1.- Installation on SdCard.

Raspberry Pi OS (previously called Raspbian). Install Raspberry Pi OS using Raspberry Pi Imager.

Installation is easy, you can follow the video. On this page I have put pictures of my installation. http://kio4.com/raspberry/1_instalacion.htm

2.- Enable VNC remote desktop.

In a terminal:

sudo raspi-config

  • Client. Viewer. In your Windows install VNC Viewer. (There is a version for LINUX)


  • Get IP of Raspberry

In a terminal:

hostname -I


3.- Install Web server. Apache. PHP.

In a Terminal.

sudo apt-get install apache2

  • Web pages will be: /var/www/html/index.html

  • sudo service apache2 restart

then in a browser:

  • In a Terminal.

sudo apt install php libapache2-mod-php

Let's create a page with the following content:

sudo nano /var/www/html/

<?php phpinfo ( ) ; ?>

then in a browser:

4.- Install Wiring Pi

Wiring Pi is a library to be able to control the pins of the Raspberry from the Terminal and from PHP, as well as other possibilities.


I used WiringPi-2.61-1.tar.gz of:


Library installation:

pi@raspberrypi:~ $ sudo su

root@raspberrypi:/home/pi# mkdir /home/pi/wiringPi

root@raspberrypi:/home/pi# cd /home/pi/wiringPi

root@raspberrypi:/home/pi/wiringPi# cp /home/pi/Downloads/WiringPi-2.61-1.tar.gz /home/pi/wiringPi/

root@raspberrypi:/home/pi/wiringPi# tar xfz WiringPi-2.61-1.tar.gz

root@raspberrypi:/home/pi/wiringPi# cd /home/pi/wiringPi/WiringPi-2.61-1

root@raspberrypi:/home/pi/wiringPi/WiringPi-2.61-1# ./build


  • Example, we can turn on/off an LED from the Terminal.

pi@raspberrypi:~ $ /usr/local/bin gpio -g mode 26 out

pi@raspberrypi:~ $ /usr/local/bin gpio -g write 26 0

pi@raspberrypi:~ $ /usr/local/bin/gpio -g write 26 1

5.- Turn on/off a LED GPIO20 from a Web page. PHP.


<meta name="viewport" content="width=device-width" />
<title>Encendido y apagado de un LED.</title>
       <center><h1>Control de un LED mediante página web</h1>
         <form method="get" action="led.php">
            <input type="submit" style = "font-size: 16 pt" value="OFF - Apagar" name="off">
            <input type="submit" style = "font-size: 16 pt" value="ON - Encender" name="on">
    shell_exec("/usr/local/bin/gpio -g mode 20 out");
                        echo "LED OFF - Apagado";
                        shell_exec("/usr/local/bin/gpio -g write 20 0");
            else if(isset($_GET['on']))
                        echo "LED ON - Encendido";
                        shell_exec("/usr/local/bin/gpio -g write 20 1");


6.- Turn on/off LED GPIO20 from App Inventor.

p9B3_on_off_RaspBerry.aia (2.2 KB)




$led= $_POST['datos'];
    shell_exec("/usr/local/bin/gpio -g mode 20 out");
    if($led == "on")
          shell_exec("/usr/local/bin/gpio -g write 20 1");
          echo "LED ON - Encendido";
    if($led == "off")
          shell_exec("/usr/local/bin/gpio -g write 20 0");
          echo "LED OFF - Apagado";


7.- Get status of Pushbutton GPIO24 from App Inventor.

It is the btn_get_status block from the previous application.


    shell_exec("/usr/local/bin/gpio -g mode 24 in");
    shell_exec("/usr/local/bin/gpio -g mode 24 up");
    $boton = shell_exec("/usr/local/bin/gpio -g read 24");
    $boton = trim($boton);
    if($boton == "1")
            echo "No Pulsado - Pushbutton UP";
            echo "Pulsado - Pushbutton DOWN";