Apache Installation

Apache HTTP Server (apache2 on Ubuntu) is the most widely deployed web server in the world. It handles serving static files, running PHP applications via mod_php or PHP-FPM, acting as a reverse proxy, and handling SSL. On Ubuntu, apache2 is managed through systemctl and configured with a modular system where you enable/disable modules and site configuration files using helper commands rather than editing the main config directly.

Apache on Ubuntu

Ubuntu Apache2 configuration model:
  /etc/apache2/
  ├── apache2.conf           ← main configuration
  ├── ports.conf             ← which ports to listen on
  ├── mods-available/        ← all installable modules
  ├── mods-enabled/          ← symlinks to enabled modules
  ├── sites-available/       ← all virtual host configs
  ├── sites-enabled/         ← symlinks to enabled sites
  └── conf-available/        ← extra configurations
      conf-enabled/          ← symlinks to enabled configs

  a2enmod  / a2dismod  — enable/disable modules
  a2ensite / a2dissite — enable/disable virtual hosts

Installing Apache

sudo apt update
sudo apt install -y apache2

# Apache starts automatically after install
# Verify:
systemctl status apache2
curl -I http://localhost

curl -I http://localhost response

HTTP/1.1 200 OK
Date: Mon, 09 Jun 2025 14:00:00 GMT
Server: Apache/2.4.58 (Ubuntu)
Content-Type: text/html
# Open firewall:
sudo ufw allow 'Apache'       # Allows port 80
sudo ufw allow 'Apache Full'  # Allows port 80 and 443

Apache directory structure

# Default web root:
ls /var/www/html/
# index.html  ← Apache default page

# Log files:
# /var/log/apache2/access.log   ← all HTTP requests
# /var/log/apache2/error.log    ← errors and server events

# Main config:
cat /etc/apache2/apache2.conf | head -50

# Enable/disable modules:
sudo a2enmod rewrite      # Enable mod_rewrite (URL rewriting)
sudo a2enmod ssl          # Enable SSL/TLS support
sudo a2dismod status      # Disable server status module
sudo systemctl reload apache2    # Apply module changes

Managing Apache with systemctl

sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2   # Full restart — drops all connections
sudo systemctl reload apache2    # Graceful reload — finishes existing requests
sudo systemctl status apache2

💡 TIP: Use reload instead of restart in production. Reload applies configuration changes gracefully, allowing existing connections to finish before the config is reloaded. Restart drops all active connections immediately.

Testing and verifying

# Always test config syntax before reloading (prevents downtime from typos):
sudo apache2ctl configtest
# OR:
sudo apachectl -t

apache2ctl configtest output (success)

Syntax OK
# View Apache version and compiled-in settings:
apache2 -V

# View enabled modules:
apache2ctl -M | sort

# Trace a request through Apache to diagnose 404s and rewrites:
curl -v http://localhost/test-page 2>&1 | head -30

Conclusion

After installing apache2, the immediate next steps are: enable the modules you need (a2enmod rewrite ssl are almost always needed), create your virtual host configs in /etc/apache2/sites-available/ and enable them with a2ensite, and always run apache2ctl configtest before each reload. The default document root /var/www/html/ is only for testing — real sites should each have their own web root like /var/www/sitename/ with appropriate ownership.

FAQ

Is Apache Installation important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support