Apache HTTP Server, commonly known as Apache, is one of the most popular web servers in the world, known for its robustness, flexibility, and modularity. Its wide range of functionalities and extensions makes it suitable for serving both static and dynamic web pages.

Ubuntu and Debian are among the preferred distributions for web hosting services due to their stability and wide community support. Both distributions provide streamlined methods to install and configure Apache, ensuring optimal performance and security out of the box.

You can install Apache on both systems using apt, and both share the same structure for files and configurations.

Steps to install and configure Apache on Ubuntu or Debian:

  1. Launch your preferred terminal application.
  2. Update the system package list.

    $ sudo apt update
    [sudo] password for user: 
    Hit:1 http://ports.ubuntu.com/ubuntu-ports lunar InRelease
    Hit:2 http://ports.ubuntu.com/ubuntu-ports lunar-updates InRelease
    Hit:3 http://ports.ubuntu.com/ubuntu-ports lunar-backports InRelease
    Hit:4 http://ports.ubuntu.com/ubuntu-ports lunar-security InRelease
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    All packages are up to date.
  3. Install the Apache package along with dependencies using apt.

    $ sudo apt install --assume-yes 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
    Suggested packages:
      apache2-doc apache2-suexec-pristine | apache2-suexec-custom
    The following NEW packages will be installed:
      apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
      libaprutil1-dbd-sqlite3 libaprutil1-ldap
    0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
    Need to get 1,866 kB of archives.
    After this operation, 13.0 MB of additional disk space will be used.
    ##### snipped
  4. Configure Apache options as necessary.

    $ sudo vi /etc/apache2/apache2.conf
  5. Test Apache configuration for errors.

     sudo apachectl configtest
    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
  6. Restart apache2 service once you are done with your configuration.

    $ sudo systemctl restart apache2
  7. Configure apache2 service to automatically start during system boot.

    $ sudo systemctl enable apache2
    Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
    Executing: /lib/systemd/systemd-sysv-install enable apache2
  8. Enable network access to port 80 (http) and 443 (https) if firewall is enabled.

    $ sudo ufw allow http
    Rules updated
    Rules updated (v6)
    $ sudo ufw allow https
    Rules updated
    Rules updated (v6)
  9. Access your web service via browser or command line tools to check if everything is working as expected.

    $ curl 127.0.0.1
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <!--
        Modified from the Debian original for Ubuntu
        Last updated: 2022-03-22
        See: https://launchpad.net/bugs/1966004
      -->
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Apache2 Ubuntu Default Page: It works</title>
        <style type="text/css" media="screen">
      * {
        margin: 0px 0px 0px 0px;
        padding: 0px 0px 0px 0px;
      }
    
      body, html {
    ##### snipped