How to Install Apache on Raspberry Pi

by

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this tutorial, you will learn how to install an Apache web server on a Raspberry Pi. I am using a Raspberry Pi 4, but any model should work.

By the end of this tutorial, you will have a basic Apache website running on your Raspberry Pi. Let’s get started.

1. Update Your System

First things first. Login to your Raspberry Pi via SSH and update your system.

sudo apt update
sudo apt upgrade

2. Install the Apache Web Server

Use the apt package manger to install the Apache web server.

sudo apt install apache2

3. Create a Basic HTML Website

Note that the default Apache configuration file at /etc/apache2/sites-available/000-default.conf has a web root directory of /var/www/html/. Remove the index.html file in this directory, and create a new file with the following content.

<!DOCTYPE html>
<html>
<head>
<title>Welcome to my Raspberry Pi!!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to my Raspberry Pi!!</h1>
<p>Hello world. This website is being served from Apache on my Raspberry Pi.</a>
<img src="Raspi-PGB001.png" width="500px"/>
</body>
</html>

Download the Raspberry Pi logo into the root directory of your website.

cd /var/www/html/
wget https://www.raspberrypi.org/app/uploads/2011/10/Raspi-PGB001.png

4. View the Website in a Browser

Don’t forget to change ownership of your website directory to the www-data user and group.

sudo chown www-data:www-data /var/www/html

To apply your changes, restart Apache with this command.

sudo systemctl restart apache2

Now you can open a web bowser, navigate to the IP address of your Raspberry Pi, and view your website that’s being served by Apache.

YouTube video


Meet Tony

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

2 thoughts on “How to Install Apache on Raspberry Pi”

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.