como-montar-un-servidor-web-apache-en-raspberry-pi

How to set up an Apache web server on Raspberry Pi

  • 2 min

Apache HTTP Server is an open-source, modular, and cross-platform web server that we can install on Raspberry Pi to serve pages and web applications.

Apache was released in 1995 and for many years was the dominant web server. Over time, alternatives such as Nginx, managed services, or applications served directly from Node.js have gained ground, but Apache remains a solid option, very well documented, and easy to install.

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.

We are going to create a basic Apache configuration on Raspberry Pi OS, enough to verify that the server works and start serving content on the local network.

Install Apache

Installing Apache on Raspberry Pi OS 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>
Copied!

Now we access the ‘localhost’ path from a web browser. If everything went correctly, we will see our sample ‘Hello world’ web page.

raspberry-apache-hola-mundo

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