Setting Web Server Raspberry Pi

Credit to this website : https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress

In order to serve web pages through Raspberry Pi, a web server application need to be installed. There are many web server applications available in the market but for this example, I used Apache which is a popular web server.

The advantage of this Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install Apache

First thing that we need to do before install a new package is we need to update the available packages in our Raspberry Pi:

sudo apt-get update

Then, install the apache2 package with this command:

sudo apt-get install apache2 -y

Test the web server

By default, Apache puts a test HTML file in the web folder.

We can check the HTML file by browsing to (use web browser) :

  1. http://localhost/
  2. http://192.168.1.10 (the ip address that our raspberry pi connect to the network) – To find the Pi’s IP address, type hostname -I at the command line.

You should see the following which means your Apache is working:

Apache success message

How to Change the  default Web Page

This default web page is is located at /var/www/html/index.html.

In the terminal, you can navigate to this directory by typing:

cd /var/www/html
ls -al

This will show you:

total 12
drwxr-xr-x  2 root root 4096 Jan  8 01:29 .
drwxr-xr-x 12 root root 4096 Jan  8 01:28 ..
-rw-r--r--  1 root root  177 Jan  8 01:29 index.html

What the columns mean

  1. The permissions of the file or directory
  2. The number of files in the directory (or 1 if it’s a file).
  3. The user that owns the file or directory
  4. The group that owns the file or directory
  5. The size of the file or directory
  6. The date and time of the last modification

This shows that by default there is one file in /var/www/html/ called index.html and it is owned by the root user (as is the enclosing folder).

In order to edit the file, you need to change its ownership to your own username. Change the owner of the file (the default pi user is assumed here) using sudo chown pi: index.html.

You can now try editing this file and then refreshing the browser to see the web page change.

The location of “localhost” normally at :  /var/www/html/

If you have a folder for example folder named “ArinProject” in this location, you can in browser like this:

http://localhost/ArinProject/