Skip to content

Installing Apache on Ubuntu the right way

A grown-up Apache install on Ubuntu — packages, service, firewall, default site, and the operational checks an MSP runs before declaring the box ready.

A fresh Ubuntu box, a domain pointed at it, and a directive to “put Apache on it.” This article is the install procedure we follow in production: get the package on, get the service running under systemd, open the firewall narrowly, confirm the default vhost responds, and leave the box in a documented state. The goal is not “Apache is running” — it is “Apache is running, observable, and ready to host a real site.”

How to verify

Before touching the package manager, check what is already there. The box may have Apache pre-installed by a base image, or Nginx may be sitting on port 80 and you are about to collide with it.

ss -ltnp | grep -E ':(80|443)\b'
dpkg -l | grep -E 'apache2|nginx'
systemctl list-unit-files | grep -E 'apache2|nginx'

If port 80 is bound, identify the process before you install. If Nginx is installed but disabled, decide whether you are replacing it or running both behind a port shuffle — there is no “they will coexist by accident” outcome.

What’s happening

Apache on Ubuntu ships as the apache2 package from the main archive. Installing it pulls in apache2-bin, apache2-utils, apache2-data, and the default MPM (apache2-mpm-event on modern releases). The post-install script creates /etc/apache2/, drops a default vhost in sites-available/000-default.conf, enables it via the sites-enabled/ symlink, registers a systemd unit, and starts the service. The default vhost binds to *:80 and serves /var/www/html/index.html.

The directory layout matters because Debian-derived distros split a single httpd.conf into many small files:

  • /etc/apache2/apache2.conf — the main entry point. Includes everything else.
  • /etc/apache2/ports.conf — Listen directives.
  • /etc/apache2/mods-available/ and mods-enabled/ — module load lines, managed by a2enmod / a2dismod.
  • /etc/apache2/sites-available/ and sites-enabled/ — vhost files, managed by a2ensite / a2dissite.
  • /etc/apache2/conf-available/ and conf-enabled/ — global config snippets (security headers, server tokens, etc.).

Everything in *-enabled/ is a symlink into the matching *-available/ directory. You edit the file in *-available/, then toggle the symlink with the helper command. Editing the symlink target directly works but bypasses the audit trail of which sites are intended to be live.

The procedure

  1. Refresh the package index and install. No surprises here, but pin to the Ubuntu archive rather than a PPA unless you have a documented reason for a newer version:

    sudo apt update
    sudo apt install -y apache2
  2. Confirm the service is up under systemd. The package starts and enables the unit automatically; verify both:

    systemctl is-active apache2
    systemctl is-enabled apache2
    sudo systemctl status apache2 --no-pager

    If the box reboots in six months, is-enabled is what saves you.

  3. Open the firewall narrowly. Ubuntu ships UFW disabled by default. If you have enabled it (and you should — see UFW basics), Apache registers application profiles you can use instead of raw port numbers:

    sudo ufw app list
    sudo ufw allow 'Apache Full'   # ports 80 and 443
    sudo ufw reload
    sudo ufw status verbose

    If you do not yet have HTTPS, Apache (port 80 only) is the narrower profile. Move to Apache Full after the cert lands.

  4. Confirm the default site responds. From the box itself first, then from outside:

    curl -I http://localhost/
    curl -I http://your.fqdn.example/

    Both should return 200 OK and Server: Apache/2.4.x (Ubuntu). If the second call fails, the problem is DNS, the cloud security group, or the host firewall — not Apache.

  5. Replace the default vhost with a real one. The 000-default file is fine for a smoke test, not for production. Create a vhost per site (see Apache virtual hosts) and disable the default once the real vhost is verified:

    sudo a2dissite 000-default.conf
    sudo apache2ctl configtest
    sudo systemctl reload apache2
  6. Lock the server tokens. By default, Apache on Ubuntu advertises its full version in the Server header. Edit /etc/apache2/conf-enabled/security.conf:

    ServerTokens Prod
    ServerSignature Off

    Reload. The Server header now reads Apache with no version — small thing, fewer fingerprinting hits.

  7. Wire logs into your aggregator. The default access log is /var/log/apache2/access.log, error log /var/log/apache2/error.log. Both rotate via /etc/logrotate.d/apache2. If you ship to Loki, Elastic, or CloudWatch, point the agent at this directory now — not after the first incident.

Common pitfalls

  • Installing Apache on a box that already has Nginx on port 80 silently fails — the unit starts but the listener binding fails; journalctl -u apache2 shows Address already in use.
  • The package starts the service before the firewall is open, so curl localhost works but external curl does not. Always test both.
  • a2enmod writes a symlink and prints “To activate the new configuration, you need to run: systemctl restart apache2” — that prompt is the only signal you owe; do not skip the restart or reload.
  • The default DocumentRoot /var/www/html is owned by root:root, which means a CGI or PHP-FPM pool running as www-data cannot write to it without a chmod or chown — this is a feature, not a bug, but it surprises first-time deployers.
  • apt upgrade will quietly bump the apache2 package across minor versions; in regulated environments, hold the package (apt-mark hold apache2) and stage upgrades in a maintenance window.

Stack Harbor stands up Apache hosts as a baseline operating model for clients running PHP, WordPress, and legacy Java fronts — install scripted, modules pinned, vhosts under config management, certificates auto-renewing. If you have an Apache fleet that grew organically and you want it brought under one operating playbook, this is the work covered by our Managed Operations practice.