This is part of a series on hosting a website on the Raspberry Pi. Click the Raspberry Pi Webserver in the Blog Series to the right for the complete steps.

Today we are getting closer to seeing our website live on your local network. With Apache installed on the Raspberry Pi and a simple addition to a hosts file, we will test a domain name today. This can be a domain name you currently own or just a made up one for today’s test. The goal of this series is to see your website live on the internet, if you don’t own a domain name, you either need to obtain a free one or purchase one.

Let’s get to installing Apache. Here is the install command.

sudo apt install apache2 -y

After installation is complete, we need to test and verify that you can see the default web page that was installed with Apache. Before doing this we need to allow port 80 (http) and port 443 (https) through the firewall. Execute these commands to allow port 80 and port 443.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status

Opening up the browser on (Windows) the computer, enter the IP address of the Raspberry Pi. In my example it is 192.168.2.26 and you should see this page displayed:

Editing the hosts file on the Windows machine, we can access our web server using a domain name. Let’s begin by adding the IP and domain name to the hosts file.

Using notepad open up the hosts file located at C:\Windows\System32\drivers\etc. Add your Raspberry Pi’s IP address, a space, and then your domain name. My example below:

Save the file and test your domain name. You should see the same Apache2 Debian Default Page again.

Check out the next post to continue the series: Installation and testing of PHP.


Share this content: