I built a web server using a Raspberry Pi – and hosted my own website on it

A Raspberry Pi is a versatile computing device with many functions, including being used as a web server to host your own website.

Raspberry Pis are single board computers widely used in DIY electronic projects and as a learning tool.

We decided to test the device as a web server.

To create a web server using Raspberry Pi, you need the base board, a MicroSD card with a capacity of 8 GB or greater, a power supply and an internet connection.

Due to the global shortage of chips, finding a new Raspberry Pi board proved difficult. Luckily we had one available from a previous experience.

We used a Raspberry Pi 3 Model B+ for this project and powered it with a micro USB cable from a charging brick.

We started creating a web server by installing the 64-bit headless version of Raspbian on our MicroSD card.

This can be done with the tool downloadable from the Raspberry Pi website.

After installing the operating system, we created an empty file named “ssh” on the boot volume to enable the SSH server.

Network configuration can also be done on the memory card, but we opted to connect directly to the Pi with an Ethernet cable and continue configuration via SSH.

We used Putty to login to the Pi. After login, we changed the default password and continued with the standard configuration.

We went through the options available in the raspi-config menu and ran ‘apt update’ and ‘apt upgrade’.

Once the Pi was set up, we followed online guides to install Nginx for the web server and Node.js for the JavaScript application we wanted to test.

We also configured a static private IP address for the Pi on our network and forwarded port 80 to the router to make the server visible on the internet.

To host the device on a mobile connection, you must use the unlimited APN for the specific network.

These are available on request for Vodacom and Cell C customers and are enabled by default for most Telkom Mobile and Afrihost Air Mobile connections.

An online port checker tool can be used to manage connections to your server. You can also start the Nginx server and browse your network’s public IP address using a device on another network.

You should be greeted with the default Nginx page if all went well.

Since we were using a standard consumer Internet connection with no static public IP address, we needed a DDNS (Dynamic Domain Name System) service.

This will maintain an up-to-date domain name with our current IP address so that the website is easily accessible to the public.

We used No-IP because it offers a free service and a guide to using it on a Raspberry Pi.

We verified that everything was working by going to the hostname we configured and getting the expected Nginx homepage.

As this server was set up to show the possibilities, the next order of business was to find an open source game that we could host.

After a short search, we came across a Snake Game by Caio Paiola on Codepen and downloaded the source code.

We copied the source code to the Pi and got it working after some troubleshooting.

All that remained was to configure crontab to automatically restart the server on a reboot. This is not necessary but saves you from having to manually restart the server after a power failure.

The site loads quickly and after playing the snake game for a minute, it’s easy to forget that it’s hosted on a Raspberry Pi sitting on my desk.

This is a perfect afternoon project for someone learning web development, where they can practice their newly learned skills.

Using a Raspberry Pi also simplified the project as technical support is readily available and easy to find using Google.

The site will be available for a few days. It should be noted that the server will be down when the mobile data connection is interrupted or in the event of a power failure.

Now read: I built an ambient backlight system for my computer screen for R600