Language: EN

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

How to set up an Apache web server on Raspberry Pi

We continue with the entries in the Raspberry Pi section. This time it’s our turn to set up 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 levels of popularity until 2005, where it dominated with 70% of the web pages hosted on Apache. Since then, its deployment has progressively declined with the growth of other solutions such as IIS, NGIX, 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 within the HTTP Server project (httpd).

In this post, we will see how to create a basic configuration of the Apache Web server on a Raspberry Pi running under Raspbian.

Install Apache

Installing Apache on Raspbian is very simple using the APT package manager. We just have to execute 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. To do this, if we are using UFW as a 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 are going to install an SSL certificate to enable access via HTTPS, ‘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. Web pages served by Apache are saved 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 has gone correctly, we will see our sample web page ‘Hello world’.

raspberry-apache-hola-mundo

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