Apache is one of the most popular web servers, while Ubuntu, based on Debian, is the most popular desktop Linux distribution. Ubuntu is increasingly being used for server deployments, and Apache has officially supported packages and modules available in Ubuntu's default apt repository.

Apache can be installed on both Ubuntu and Debian from the command line using apt.

Steps to install and configure Apache on Ubuntu or Debian:

  1. Launch your preferred terminal application.
  2. Sync apt's package list from the default repository.

    $ sudo apt update [sudo] password for user: Hit:1 http://jp.archive.ubuntu.com/ubuntu eoan InRelease Get:2 http://jp.archive.ubuntu.com/ubuntu eoan-updates InRelease [97.5 kB] Get:3 http://jp.archive.ubuntu.com/ubuntu eoan-backports InRelease [88.8 kB] Get:4 http://jp.archive.ubuntu.com/ubuntu eoan-security InRelease [97.5 kB] Fetched 284 kB in 2s (166 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date.

  3. Install apache2 package along with dependencies using apt.

    $ sudo apt install --assume-yes apache2 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed:   apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert Suggested packages:   apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser openssl-blacklist The following NEW packages will be installed:   apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert 0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded. Need to get 1,866 kB of archives. After this operation, 8,062 kB 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: 2016-11-16     See: https://launchpad.net/bugs/1288690   -->   <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