Install Apache HTTP Server on Debian 11

This guide serves as quick demo on how to install Apache HTTP server on Debian 11. Apache is the number one HTTP server on the Internet for modern operating systems including UNIX and Windows. Apache provides a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

Install Apache HTTP Server on Debian 11

To install Apache HTTP server on Debian 11;

Run system Update

Ensure your system package cache is up-to-date by executing the commands below;

apt update
apt upgrade

Install Apache HTTP Server on Debian 11

Apache is available on the default Debian 11 repositories/sources lists.

apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.4.48-3.1+deb11u1
  Version table:
     2.4.48-3.1+deb11u1 500
        500 http://security.debian.org/debian-security bullseye-security/main amd64 Packages
     2.4.48-3.1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages

Thus, the installation can be easily done by running the command below;

apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcurl4 liblua5.3-0 ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcurl4 liblua5.3-0 ssl-cert
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,786 kB of archives.
After this operation, 9,122 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Running Apache Service

Once the command above completes, Apache should now be installed on your Debian 11 server.

When installed, it is started automatically;

systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-08-20 08:20:05 EAT; 14s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 1441 (apache2)
      Tasks: 55 (limit: 1133)
     Memory: 9.0M
        CPU: 38ms
     CGroup: /system.slice/apache2.service
             ├─1441 /usr/sbin/apache2 -k start
             ├─1443 /usr/sbin/apache2 -k start
             └─1444 /usr/sbin/apache2 -k start

Aug 20 08:20:05 debian11 systemd[1]: Starting The Apache HTTP Server...
Aug 20 08:20:05 debian11 apachectl[1440]: AH00557: apache2: apr_sockaddr_info_get() failed for debian11
Aug 20 08:20:05 debian11 apachectl[1440]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' di>
Aug 20 08:20:05 debian11 systemd[1]: Started The Apache HTTP Server.

Also, it is enabled to run on system boot;

systemctl is-enabled apache2

Sample output;

enabled

If for some reason it is not started nor enabled to run on boot, simply run the command below to start and enable it to run on system boot;

systemctl enable --now apache2

You can restart or reload Apache2 service by running the commands below, respectively;

systemctl restart apache2
systemctl reload apache2

Accessing Apache Web Pages

You can access Apache web pages via the address http://server-IP-or-domain. By default, you will be served with a default Apache web page;

Install Apache HTTP Server on Debian 11

If you want to restrict access to various services running on your Debian 11 server, simply install UFW.

apt install ufw -y

Enable UFW. Before you can do this, ensure that you allow the IP from which you SSHed from;

ufw allow from YOUR_IP to any port 22 proto tcp
ufw enable

Next, Open Apache ports on firewall;

ufw allow "WWW Full"

Creating a Simple Apache Web Page

You can now create your custom pages and virtual hosts to define how these pages are served.

For example, to serve a simple html page, create your site configuration for that page;

cat > /etc/apache2/sites-available/itnixpro.conf << EOL
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
    	ServerName itnixpro.com
    	ServerAlias www.itnixpro.com
	DocumentRoot /var/www/html

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOL

Create your page on the Apache DocumentRoot directory. You can run the command below to create a simple HTML page;

cat > /var/www/html/index.html << 'EOL'
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="content">
<center>
  <h1>itnixpro.com sample HTML page.</h1>
</center>
</div>
</body>
</html>
EOL

Check Apache configuration syntax;

apachectl -t

If the out is, Syntax OK, proceed to enable the site.

a2ensite itnixpro.conf

Disable the default site;

a2dissite 000-default.conf

Restart Apache;

systemctl restart apache2

Accessing your page, http://server-IP-or-hostname.

Sample page;

Install Apache HTTP Server on Debian 11

And that is how you can install Apache HTTP server on Debian 11.

Other Tutorials

Install Debian 11 Bullseye on VirtualBox

Install Usermin on Rocky Linux 8

Install Webmin on Rocky Linux 8

Founder of itnixpro.com|Linux Engineer|Author at Itnixpro.com

Leave a Comment