How to install Apache on Debian 10

Apache is one of the most used webserver, with a large community and lots of documentation

Facts about apache:

  • apache2 package from Debian sources is not the latest version
  • by default is running on port 80; if this port is used the service will crash during start-up
  • by default is listening on all network interfaces, so be careful
  • when you want to use some parameters in virtual hosts , check that module containing what you need is activated; as an example for https you need mod ssl
  • secure it before going to production, don’t let de default options
  • activate only the modules you need and keep your configuration files under control
  • don’t abuse .httaccess; at every request, apache is checking it even if it”s not needed
  • configure http and https default virtual host to point to a default page, don’t expose apache by using the default page
  • http2 is not activated by default when using https

Installation

Apache packages are available in the default Debian repositories. You need to update the package index and install the webserver using the following commands:

sudo apt -y  update
sudo apt -y install apache2

Wait for the command to finish and check that service is running:

catalin@devops:$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-05-03 17:44:36 UTC; 1s ago
     Docs: https://httpd.apache.org/docs/2.4/
  Process: 29296 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 29301 (apache2)
    Tasks: 55 (limit: 9508)
   Memory: 9.8M
   CGroup: /system.slice/apache2.service
           ├─29301 /usr/sbin/apache2 -k start
           ├─29302 /usr/sbin/apache2 -k start
           └─29303 /usr/sbin/apache2 -k start

May 03 17:44:36 devops systemd[1]: Starting The Apache HTTP Server...
May 03 17:44:36 devops systemd[1]: Started The Apache HTTP Server.

Open your browser and type http://hostname:80 or http://ip:80 and you should see the default Apache page.