This article is to provide step by step instructions for making Raspberry Pi as a web server where we can publish our web pages over local network. Apache is a prevalent web server application you can introduce on the Raspberry Pi to permit it to serve pages. All alone, Apache can serve HTML documents over HTTP, and with extra modules can serve element website pages utilizing scripting tools, for example, PHP. The fundamental services which are required to turn your Raspberry Pi into a web server are, Apache (the web server itself), PHP (scripting language).
In this project the Raspberry Pi board is booted with the Ubuntu OS and is connected to the Ethernet port of a Windows7 PC. The board is connected to the internet connection as explained in the article Connecting the Raspberrypi to the internet. The IP address of the Raspberry Pi board has been obtained to remote login in the TUI using the PUTTY and is remotely accessed using VNC.
Make sure you’re up-to-date:
To check for update and to install them enter the following command:
sudo apt-get update
First, we have to install the apache2 package by entering the following command:
Sudo apt-get install apache2 apache2-doc apache2-utils
Fig. 2: Apache Installation Command In Raspberry Pi
This shouldn’t take long, press ‘y’ to continue installation.
Test The Web Server:
Once the installation is finished, check the server by navigating any browser to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi’s IP address) from another computer on the Local Area Network you should see the following. To find the Pi’s IP address, type hostname -I at the command line.
Fig. 3: Testing Of Web Server Browse On The Pi Through http://localhost/
To allow your Apache server to process PHP files, you’ll need to install PHP5 module for Apache. Type the following command to install these:
sudo apt-get install php5 libapache2-mod-php5
Fig. 4: Installing PHP5 To Process PHP Files In Apache
Copying web page files:
Navigate to ‘www’ folder by entering this command:
Now remove the index.html file and create the file index.php by following two commands
sudo rm index.html
sudo nano index.php
Now your Apache server is capable of handling some PHP content also:
<?php echo “hello world”;
You should see “hello world” when you save and refresh your browser.
Try something dynamic by fetching date and time details.
<?php echo date(‘Y-m-d H:i:s’);
or show your PHP info:
Fig. 5: Testing PHP Code In Raspberry Pi Apache Server