Building a Web Server for $27 (~€25)? Here’s How You Can Do It!

The Raspberry Pi Zero 2 W is a tiny yet incredibly versatile mini-computer, making it an ideal foundation for building a cost-effective web server. In this article, we will guide you step-by-step on how to set up a fully functioning web server using the Pi Zero 2 W, from acquiring the hardware to installing the software and configuring security settings.

Table of Contents

  1. Required equipment for the project
  2. Basics: What is Raspberry Pi Zero 2 W?
  3. Why use a Raspberry Pi for a web server?
  4. Installing the operating system
  5. Setting up SSH connection
  6. Installing Apache web server
  7. Installing PHP and MySQL
  8. Uploading your website
  9. Security settings
  10. FAQ – frequently asked questions
  11. Future expansion possibilities

1. Required equipment for the project

  • Raspberry Pi Zero 2 W
  • microSD card (at least 16GB, Class 10)
  • microSD card reader
  • Power cable (micro-USB)
  • Wi-Fi connection
  • Case or protective housing (optional)
  • Computer for initial setup

2. Basics: What is Raspberry Pi Zero 2 W?

The Raspberry Pi Zero 2 W is a compact mini-PC powered by a 1 GHz quad-core ARM Cortex-A53 processor. With built-in Wi-Fi and Bluetooth, it is an excellent choice for various IoT projects and small web servers.

3. Why use a Raspberry Pi for a web server?

  • Cost-effective: You can build a functioning web server with minimal investment.
  • Energy-efficient: Extremely low power consumption.
  • Learning opportunity: Great for learning Linux, web servers, and networking.
  • Scalable: Suitable for personal projects and hosting smaller community sites.

4. Installing the operating system

Required software

  • Raspberry Pi Imager (available for Windows, macOS, and Linux)
  • Raspberry Pi OS Lite (headless version)

Steps

  1. Download and install the Raspberry Pi Imager.
  2. Select Raspberry Pi OS Lite as the operating system.
  3. Write it to the SD card.
  4. Add an empty file named “ssh” to the /boot directory to enable SSH.
  5. Create the wpa_supplicant.conf file to connect the Pi to Wi-Fi.

5. Setting up SSH connection

  • Boot the Pi.
  • Use an SSH client (e.g., PuTTY on Windows) to access the IP address.
  • Default login credentials: username: pi, password: raspberry
ssh pi@<IP-address>

6. Installing Apache web server

sudo apt update
sudo apt install apache2 -y
  • The web server will immediately be accessible via the Pi’s IP address.
  • The default test page is located in the /var/www/html directory.

7. Installing PHP and MySQL

Installing PHP

sudo apt install php libapache2-mod-php -y

Installing MySQL (or MariaDB)

sudo apt install mariadb-server php-mysql -y
  • Setting up the database:
sudo mysql_secure_installation

8. Uploading your website

  • Replace the /var/www/html/index.html file with your own website files.
  • Use the scp command to transfer files:
scp index.html pi@<IP-address>:/var/www/html/

9. Security settings

  • Regularly update the software:
sudo apt update && sudo apt upgrade -y
  • Use a strong password.
  • Install a firewall:
sudo apt install ufw
sudo ufw allow 'Apache'
sudo ufw enable
  • Use an SSL/TLS certificate (Let’s Encrypt)

10. FAQ – frequently asked questions

Will it work with dynamic IP?

  • Yes, but using a dynamic DNS service is recommended.

How many websites can I host?

  • The Pi Zero 2 W has limited performance but can handle several small sites without issues.

Which web frameworks can I install?

  • WordPress, Joomla, and Drupal can all be run.

11. Future expansion possibilities

  • Installing HTTPS certificates
  • Setting up automatic backups
  • Fully optimizing the LAMP stack
  • Running web applications like a Nextcloud server

With that, your own Raspberry Pi Zero 2 W web server is ready! Simple, affordable, and a fantastic opportunity to dive into the world of server administration.