Visit my website New

Sunday, 20 December 2015

Raspberry Pi Apache Server Led ON OFF

Install Apache

Apache is a Popular web server, it can serve HTML files over HTTP, and with additional modules can serve dynamic webpages using scripting language such as PHP. It can be installed on Raspberry Pi.

First install apache2 package

sudo apt-get install apache2 -y

Test the web server 

By default, Apache puts a test HTML file in the web folder. The default webpage is served when you browse to http://localhost/ on the pi itself or (Your Pi's ip address).

raspberry pi default apache page

This means you have Apache working!

The default webpage is just html file on the system. It is located at /var/www/index.html

Navigate to this directory in the terminal and have a look at what's inside
cd  /var/www/ 

ls -al

This shows the content of the file along with user which owns the file, file size and last modification date & time.

Additional -Install PHP

PHP helps to execute the python file dynamically on the webpage. To install PHP on Raspberry Pi,
sudo apt-get install php5 libapache5-mod-php5

Creating a PHP file to execute the python file on the webpage:

Move to the directory /var/www 

Create a file named index.php and place the following codes.

Download the index.php file
The webpage could look like below

The python file for each button should be like this
LED ON (      LED OFF (


  1. Downloading thanks, ill try and let you know! :)

  2. Hello,

    How did you manage to activate the CGI so that you can run the python program from the web?

  3. what is site .css file can i get

    1. sorry i don't have now. I might have deleted it. CSS is style sheet, it gives good looking buttons. You add your own.

  4. where i store program file(light1,light0)

    1. the same location where index.php is placed

  5. Hi, i have successfully created the index.php file, but i can not control the leds open when i press the web server. Can u help me ? :) Thank u very much....

  6. I'm using a raspi v3 I'm using a 5v relay board instead of LEDs I have followed your instructions and have been able to access the index page you created without any problems.

    However, I am not able to activated the relays.

    Any assistance you can provide would be appreciated.

  7. I am designing a program to monitor sensors, and control equipment, I added index.php to main.html program, when I pressed a button the program give me a message "405 method not allowed ?"
    This the first time to use html, php and python (I am 68 years old)

  8. Hi. I have just tried it now but unfortunately the last step doesn't work for me. I mean blink an LED. I have the website running etc but when I press turn on nothing happens. (Yes, I added files to the same directory as the index.php

  9. The buttons don't do anything. I have the the correct scrips and they work when I manually call them in terminal. Please help!!!!!