How to Install Apache Web Server on Debian 10 Linux

Posted 

3 min read

Apache HTTP server is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that powers a large percentage of the Internet's websites. Apache provides many powerful features that can be extended through additional modules.

In this tutorial, we'll explain how to install Apache on Debian 10, Buster.

Prerequisites

Before starting with the tutorial, make sure you are logged in as a user with sudo privileges.

Installing Apache

Apache packages are available in the default Debian repositories.

The installation is pretty straightforward. Update the package index and install the Apache web server with the following commands:

sudo apt update
sudo apt install apache2

That's it, Apache is installed and automatically started. To check the status type:

sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: 
   Active: active (running) since Sat 2019-07-27 13:55:49 PDT; 21s ago
   ...

Adjust the Firewall

UFW users can open HTTP (80) and HTTPS (443) ports by enabling the ‘Nginx Full’ profile:

sudo ufw allow 'Apache Full'

If you are using nftables to filter connections to your system, open the necessary ports by issuing the following command:

nft add rule inet filter input tcp dport {80, 443} ct state new,established counter accept

Verifying Apache Installation

To verify that Apache works correctly, open your browser, type your server IP address or domain name http://YOUR_IP_OR_DOMAIN/, and you will see the default Apache welcome page as shown below:

The page contains basic information about Apache configuration files, helper scripts, and directory locations.

Apache Configuration File's Structure and Best Practices

  • In Debian based systems Apache configuration files are located in the /etc/apache2 directory.
  • The main Apache configuration file is /etc/apache2/apache2.conf.
  • The ports that Apache will listen to are specified in the /etc/apache2/ports.conf file.
  • Apache Virtual Hosts files are located in the /etc/apache2/sites-available directory. The configuration files found in this directory are not used by Apache unless they are linked to the /etc/apache2/sites-enabled directory.
  • You can activate a virtual host directive by creating a symlink using the a2ensite command from the configuration files found in the sites-available directory to the sites-enabled directory. To deactivate a virtual host use the a2dissite command.
  • It is highly recommended to follow the standard naming convention, for example, if your domain name is mydomain.com then the domain configuration file should be named /etc/apache2/sites-available/mydomain.com.conf
  • Configuration files that are used for loading various Apache modules are located in the /etc/apache2/mods-available directory. Configurations in the mods-available directory can be enabled by creating a symlink to the /etc/apache2/mods-enable directory using the a2enconf command and disabled with the a2disconf command.
  • Files containing global configuration fragments are stored in the /etc/apache2/conf-available directory. Files in the conf-available directory can be enabled by creating a symlink to the /etc/apache2/conf-enabled using the a2enconf command and disabled with the a2disconf command.
  • Apache log files (access.log and error.log) are located in the /var/log/apache directory. It is recommended to use different access and error log files for each virtual host.
  • You can set your domain document root directory to any location you want. The most common locations for webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

Conclusion

Installing Apache on Debian is a matter of running a single command.

You can now start deploying your applications and use Apache as a web or proxy server.

If you have any questions or feedback, feel free to leave a comment.