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—Listendirectives./etc/apache2/mods-available/andmods-enabled/— module load lines, managed bya2enmod/a2dismod./etc/apache2/sites-available/andsites-enabled/— vhost files, managed bya2ensite/a2dissite./etc/apache2/conf-available/andconf-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
-
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 -
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-pagerIf the box reboots in six months,
is-enabledis what saves you. -
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 verboseIf you do not yet have HTTPS,
Apache(port 80 only) is the narrower profile. Move toApache Fullafter the cert lands. -
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 OKandServer: Apache/2.4.x (Ubuntu). If the second call fails, the problem is DNS, the cloud security group, or the host firewall — not Apache. -
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 -
Lock the server tokens. By default, Apache on Ubuntu advertises its full version in the
Serverheader. Edit/etc/apache2/conf-enabled/security.conf:ServerTokens Prod ServerSignature OffReload. The
Serverheader now readsApachewith no version — small thing, fewer fingerprinting hits. -
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 apache2showsAddress already in use. - The package starts the service before the firewall is open, so
curl localhostworks but externalcurldoes not. Always test both. a2enmodwrites 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/htmlis owned byroot:root, which means a CGI or PHP-FPM pool running aswww-datacannot write to it without a chmod or chown — this is a feature, not a bug, but it surprises first-time deployers. apt upgradewill 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.