Advance

How to install Apache Web Server on Debian 10

How to install Apache Web Server on Debian 10
0
(0)

To introduce and install the most widely-used web server in the world, in this article, you will learn how to install Apache Web Server on Debian 10.

The Apache HTTP Server provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.

 

Prerequisites

The tutorial may be more useful if you know:

How to install Apache Web Server on Debian 10

Join us to walk through the steps of this guide to learn how to install an Apache web server on your Debian 10 server.

 

1- Installing Apache

As the Apache is available within Debian’s default software repositories, it helps us to install it using conventional package management tools.

First, update the local package index:

sudo apt update  

Then, install the apache2 package:

sudo apt install apache2  

 

Do not miss related articles:

How to Install Apache on Windows Server

2- Adjusting the Firewall

You must modify the firewall settings to allow outside access to the default web ports and then test apache. As you read in Prerequisites, you need to have a UFW firewall configured to restrict access to your server.

To provide a few application profiles, Apache registers itself with UFW. So you will use it to enable or disable access to Apache through the firewall.

To list the ufw application profiles:

sudo ufw app list  
Output
Available applications:    AIM    Bonjour    CIFS  . . .    WWW   WWW Cache   WWW Full   WWW Secure  . . .

 

In the following, you can review some Apache profiles examples that begin with WWW:

This profile opens only port 80 (normal, unencrypted web traffic): WWW

And this profile opens only port 8080 (sometimes used for caching and web proxies): WWW Cache:

Also, this profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic): WWW Full:

Finally, this profile opens only port 443 (TLS/SSL encrypted traffic): WWW Secure:

It is better to enable the most restrictive profile that will still allow the traffic you’ve configured. In this guide, we did not configure SSL for our server, so we will only need to allow traffic on port 80:

sudo ufw allow 'WWW'  

To verify the change:

sudo ufw status  
Output
Status: active    To                         Action      From  --                         ------      ----  OpenSSH                    ALLOW       Anywhere  WWW                        ALLOW       Anywhere  OpenSSH (v6)               ALLOW       Anywhere (v6)  WWW (v6)                   ALLOW       Anywhere (v6)

 

 

3- Checking your Web Server

At the end of the installation process, Debian 10 starts Apache, while the server is already up and running.

To make sure the service is running, check with the systemd init system

sudo systemctl status apache2  
Output
● apache2.service - The Apache HTTP Server     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)     Active: active (running) since Fri 2019-07-19 15:33:01 UTC; 4min 13s ago       Docs: https://httpd.apache.org/docs/2.4/    . . .    Jul 19 15:33:01 debssh systemd[1]: Starting The Apache HTTP Server...  Jul 19 15:33:01 debssh apachectl[2791]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive global  Jul 19 15:33:01 debssh systemd[1]: Started The Apache HTTP Server.

 

Any output like the above means that the service has started successfully. But we offer you to request a page from Apache for the best way of testing.

Also, you can access the default Apache landing page to confirm that the software is running properly through your IP address. Get your server’s IP address, if you do not know that in a few different ways from the command line.

hostname -I  

You get back a few addresses separated by spaces, try each in your web browser to see if they work.

You can use the curl tool, which should give you your public IP address as seen from another location on the internet.

To install curl using apt:

sudo apt install curl  

Then, use curl to retrieve icanhazip.com using IPv4:

curl -4 icanhazip.com  

Next, enter your server’s IP address into your browser’s address bar:

http://your_server_ip

 

The following page should appear which means that Apache is working correctly. You can also review some basic information about important Apache files and directory locations.

default Debian 10 Apache web page

 

 4- Managing the Apache Process

You can go over some basic management commands, as you have your web server up and running till here.

To stop your web server:

sudo systemctl stop apache2  

Use the below command to start the web server.

sudo systemctl start apache2  

When you need to stop and then start the service again, type:

sudo systemctl restart apache2  

Apache can often reload without dropping connections if you are simply making configuration changes:

sudo systemctl reload apache2  

To re-enable the service to start up at boot, use the below command.

sudo systemctl enable apache2  

At this point, Apache starts automatically when the server boots again.

 

 

You can use virtual hosts,(similar to server blocks in Nginx) when using the Apache web server.

Apache on Debian 10 has one server block enabled by default that is configured to serve documents from the /var/www/html directory. Create the directory for your_domain as follows, using the -p flag to create any necessary parent directories:

Note: Do not forget to replace your_domain with your own domain name

sudo mkdir -p /var/www/your_domain  

Next, assign ownership of the directory with the $USER environmental variable:

sudo chown -R $USER:$USER /var/www/your_domain  

In case you haven’t modified your unmask value, the permissions of your web roots should be correct. To make sure of that, type:

sudo chmod -R 755 /var/www/your_domain 

Use your preferred editor or nano, to create a sample index.html page.

nano /var/www/your_domain/index.html  

Then, add the following sample HTML inside:

/var/www/your_domain/index.html
<html>      <head>          <title>Welcome to your_domain!</title>      </head>      <body>          <h1>Success!  The your_domain virtual host is working!</h1>      </body>  </html>

you can save and close the file now.

 

To let Apache serve this content, you must create a virtual host file with the correct directives. To do this, instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, make a new one at /etc/apache2/sites-available/your_domain.conf:

sudo nano /etc/apache2/sites-available/your_domain.conf  
/etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>      ServerAdmin admin@your_email_domain      ServerName your_domain      ServerAlias www.your_domain      DocumentRoot /var/www/your_domain      ErrorLog ${APACHE_LOG_DIR}/error.log      CustomLog ${APACHE_LOG_DIR}/access.log combined  </VirtualHost>

 

Now, you can enable the file with the a2ensite tool:

sudo a2ensite your_domain.conf  

Next, disable the default site defined in 000-default.conf:

sudo a2dissite 000-default.conf  

You can test for configuration errors, using the below command:

sudo apache2ctl configtest  
Output
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message  Syntax OK

To implement your changes, restart Apache

sudo systemctl restart apache2  

It is the point in which Apache would be serving your domain name. Also, you can test it by navigating to http://your_domain, where you should see something like below:

serving your domain name

 

 

6- Getting Familiar with Important Apache Files and Directories

After getting familiar with managing the Apache service itself, let’s take a few minutes to familiarize yourself with a few important directories and files.

Content

/var/www/html: The actual web content, which by default only consists of the default Apache page you saw earlier, is served out of the /var/www/html directory. Also, you changed by altering Apache configuration files.

 

Server Configuration

/etc/apache2: The Apache configuration directory. All of the Apache configuration files reside here.

/etc/apache2/apache2.conf: The main Apache configuration file. you can use it to modify and to make changes to the Apache global configuration. This file is responsible for loading many of the other files in the configuration directory.

/etc/apache2/ports.conf: This file specifies the ports that Apache will listen on. By default, Apache listens on port 80 and additionally listens on port 443 when a module providing SSL capabilities is enabled.

/etc/apache2/sites-available/: The directory where per-site virtual hosts can be stored. Apache will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Typically, all server block configuration is done in this directory and then enabled by linking to the other directory with the a2ensite command.

/etc/apache2/sites-enabled/: The directory where enabled per-site virtual hosts are stored. Typically, these are created by linking to configuration files found in the sites-available directory with the a2ensite. Apache reads the configuration files and links found in this directory when it starts or reloads to compile a complete configuration.

/etc/apache2/conf-available//etc/apache2/conf-enabled/: These directories have the same relationship as the sites-available and sites-enabled directories, but are used to store configuration fragments that do not belong in a virtual host. Files in the conf-available directory can be enabled with the a2enconf command and disabled with the a2disconf command.

/etc/apache2/mods-available//etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively. Files in ending in .load contain fragments to load specific modules, while files ending in .conf contain the configuration for those modules. Modules can be enabled and disabled using the a2enmod and a2dismod command.

Recommended Article: How to install Apache Web Server on Debian 10

Server Logs

/var/log/apache2/access.log: By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise.

/var/log/apache2/error.log: By default, all errors are recorded in this file. The LogLevel directive in the Apache configuration specifies how much detail the error logs will contain.

 

Good job! by finishing this tutorial, you know that you have your web server installed, you have many options for the type of content you can serve and the technologies you can use to create a richer experience.

 

Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problems in it.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day