Visit my website www.sarathiblog.com 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 http://192.168.10.1 (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 (light1.py)      LED OFF (light0.py)


12 comments :

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

    ReplyDelete
  2. Hello,

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

    ReplyDelete
  3. what is site .css file can i get

    ReplyDelete
    Replies
    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.

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

    ReplyDelete
    Replies
    1. the same location where index.php is placed

      Delete
  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....

    ReplyDelete
  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.

    ReplyDelete
  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)

    ReplyDelete
  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

    ReplyDelete
  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!!!!!

    ReplyDelete