We continue with the posts in the Raspberry Pi section. This time, we are going to configure a web server with the popular Apache, an open-source, modular, and cross-platform HTTP web server.
Apache was released in 1995 and maintained high popularity levels until 2005, where it dominated with 70% of websites hosted on Apache. Since then, its deployment has progressively declined with the growth of other solutions like IIS, NGINX, or NodeJS. However, Apache remains one of the main alternatives for setting up a Web server.
The Apache server is developed and maintained by a community of users under the supervision of the Apache Software Foundation as part of the HTTP Server (httpd) project.
In this post, we will see how to create a basic configuration of the Apache Web server on a Raspberry Pi running Raspbian.
Install Apache
Installing Apache on Raspbian is very easy using the APT package manager. We simply need to run the following commands.
sudo apt update sudo apt install apache2
Configure the Firewall for Apache
To be able to access the pages served by Apache, we must allow connections in the Firewall. For this, if we are using UFW as the firewall, first we list the applications that are running.
sudo ufw app list
Next, we add ‘Apache’ to the allowed applications.
sudo ufw allow Apache
If we later plan to install an SSL certificate to enable HTTPS access, we allow ‘Apache Full’.
sudo ufw allow Apache Full
Test Apache
To test that everything is working correctly, first, we check the status of Apache.
sudo systemctl status apache2
Next, we will create a sample web page. The web pages served by Apache are stored in the ‘www/html’ path and subfolders. Therefore, we use the following command to create an ‘index.html’ file that will be our ‘Hello world’ web page.
nano /var/www/html/index.html
In this file, we create the following:
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Hello world!</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>This is your web page. Congratulations!</h1>
</body>
</html>
Now we access the ‘localhost’ path from a web browser. If everything went correctly, we will see our sample ‘Hello world’ web page.

Congratulations, you have correctly configured Apache on your Raspberry Pi! In the next post, we will see how to implement virtual environments in Apache.

