Turn Your Raspberry Pi Into a Web Server With Apache

Want to host your own website from home using a Raspberry Pi? Apache makes it easy! In this guide, you'll learn how to install and run a simple Apache web server on your Raspberry Pi.


What You Need

  • Raspberry Pi with Raspberry Pi OS (Lite or Desktop)
  • Internet connection
  • Terminal or SSH access

Step-by-Step Guide

1. Update Your System

sudo apt update && sudo apt upgrade

2. Install Apache Web Server

sudo apt install apache2 -y

This installs Apache and starts the web server automatically.

3. Check If It Works

Open your browser and go to:

http://your_pi_ip_address

You should see the default Apache welcome page.

4. Find Your Raspberry Pi’s IP Address

hostname -I

5. Set Up Your Web Page

The default web root folder is:

/var/www/html/

To change the homepage, edit or replace the index.html file:

sudo nano /var/www/html/index.html

Optional: Install PHP (For Dynamic Sites)

sudo apt install php libapache2-mod-php -y

Then create a test PHP file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://your_pi_ip/info.php


Done!

You now have a working web server on your Raspberry Pi. You can host static websites, local dashboards, or even full apps like WordPress.


Bonus Tips

  • Use sudo systemctl restart apache2 to restart Apache
  • Secure with a firewall like ufw or reverse proxy like Nginx
  • Use a free dynamic DNS service to access your Pi from anywhere

Turning your Pi into a server is a great project for learning Linux, web hosting, and self-hosting. Enjoy building your own mini internet!

Comments