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
This means you have Apache working!
The default webpage is just html file on the system. It is located at
Navigate to this directory in the terminal and have a look at what's inside
This shows the content of the file along with user which owns the file, file size and last modification date & time.
http://localhost/
on the pi itself or http://192.168.10.1
(Your Pi's ip address).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
Create a file named
Download the index.php file
The webpage could look like below
/var/www
Create a file named
index.php
and place the following codes.Download the index.php file
The webpage could look like below
Downloading thanks, ill try and let you know! :)
ReplyDeleteHello,
ReplyDeleteHow did you manage to activate the CGI so that you can run the python program from the web?
Thank you!
ReplyDeletewhat is site .css file can i get
ReplyDeletesorry i don't have now. I might have deleted it. CSS is style sheet, it gives good looking buttons. You add your own.
Deletewhere i store program file(light1,light0)
ReplyDeletethe same location where index.php is placed
DeleteHi, 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....
ReplyDeleteI'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.
ReplyDeleteHowever, I am not able to activated the relays.
Any assistance you can provide would be appreciated.
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 ?"
ReplyDeleteThis the first time to use html, php and python (I am 68 years old)
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
ReplyDeleteThe buttons don't do anything. I have the the correct scrips and they work when I manually call them in terminal. Please help!!!!!
ReplyDelete