Learn to create and using the Apache web server in Raspberry Pi. Apache is one of the most popular web server applications used in Raspberry Pi to server web pages. Apache can serve HTML files over an HTTP connection. To serve dynamic web pages, languages such as PHP and JS is used. So, let’s start.
Step 1: Install Apache in Raspberry Pi
Start the Terminal window in Raspberry Pi and install Apache2 by entering below given command.
sudo apt-get install apache2 -y
Step 2: Testing the Apache webserver.
By default, Apache has test HTML files in the web folder. This page will be served at the localhost on Raspberry Pi and will be accessed through the following ways.
http://"ip address of your Raspberry Pi"/
Step 3: Build an Advanced Webpage
Follow the below-given steps to build the Apache web server in Raspberry Pi.
- Change default page located at “/var/www/html/index.html”
- To edit this file, you need to change ownership to your username. Assuming your username is Pi, use the following code to change ownership.
sudo chown pi: index.html
- Change the contents of “index.html” to your preferred HTML content and save the file. For testing purposes, you can use HTML contents form this page. The HTML content is in step 3 of the page.
- For using PHP, you must save the file as “index.php”
- To see changes take place, go to the browser and reload the page.
Using the Apache server you can view your web pages on another computer connected to the same network.
Learn basic hardware information of Raspberry Pi 3.