Apache HTTP Server is a widely-used web server designed for flexibility and modularity, making it suitable for serving both static and dynamic content. Its extensive set of features and available modules allow for tailored configurations based on the needs of different applications.

Ubuntu and Debian are popular Linux distributions often chosen for web hosting due to their stability and strong community support. Both distributions facilitate the installation and configuration of Apache using the apt package manager, streamlining the process for users and ensuring consistency across different environments.

Installing Apache on these systems involves using common commands to manage packages and configure the server. By following the necessary steps, Apache can be set up to meet specific requirements, allowing for optimal performance and security on Ubuntu and Debian systems.

Steps to install and configure Apache on Ubuntu and Debian:

  1. Open your terminal application.
  2. Update the package list to ensure the latest packages are available.
    $ 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 Apache2 package along with its dependencies.
    $ 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. Modify the Apache configuration file as needed.
    $ sudo vi /etc/apache2/apache2.conf
  5. Test the configuration to check 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 the Apache2 service to apply the changes.
    $ sudo systemctl restart apache2
  7. Enable the Apache2 service to start automatically on 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. Configure the firewall to allow HTTP and HTTPS traffic if firewall is enabled.
    $ sudo ufw allow http
    Rules updated
    Rules updated (v6)
    $ sudo ufw allow https
    Rules updated
    Rules updated (v6)
  9. Verify that Apache is running by accessing it through a web browser.
    $ 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

This guide is tested on Ubuntu:

Version Code Name
22.04 LTS Jammy Jellyfish
23.10 Mantic Minotaur
24.04 LTS Noble Numbat
Discuss the article:

Comment anonymously. Login not required.