How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Install the Apache Web Server on Ubuntu
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Install the Apache Web Server on Ubuntu
Server Management

How to Install the Apache Web Server on Ubuntu

how7o
By how7o
Last updated: May 22, 2026
7 Min Read
Install the Apache web server on Ubuntu
SHARE

To install the Apache web server on Ubuntu, run sudo apt install apache2, open port 80 in the UFW firewall, and verify with systemctl status apache2. After that, set up virtual hosts under /etc/apache2/sites-available/ to serve multiple domains from the same server.

Contents
  • Prerequisites
  • Step 1: Install Apache
  • Step 2: Open the firewall
  • Step 3: Verify Apache is running
  • Step 4: Set up a virtual host
  • Managing Apache with systemctl
  • Where Apache puts its files
  • Next steps
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on Ubuntu 22.04 with Apache 2.4. Originally published 2023-03-09, rewritten and updated 2026-05-17.

Prerequisites

  • An Ubuntu server (22.04 LTS or 24.04 LTS recommended).
  • A non-root user with sudo privileges.
  • UFW firewall enabled (sudo ufw enable if you haven’t already).

Step 1: Install Apache

sudo apt update
sudo apt install apache2 -y

The apache2 package installs the server, the systemd unit, and a default site under /var/www/html. It also enables and starts the service automatically.

Install Apache on Ubuntu — apt install, UFW profile, virtual host setup, systemctl reload

Step 2: Open the firewall

sudo ufw app list

This lists Apache’s UFW profiles:

  • Apache — opens port 80 (HTTP only).
  • Apache Full — opens 80 and 443 (HTTP + HTTPS).
  • Apache Secure — opens only 443 (HTTPS).
sudo ufw allow 'Apache'
sudo ufw status

Switch to 'Apache Full' after you set up TLS with Certbot.

Step 3: Verify Apache is running

sudo systemctl status apache2

The output should show active (running). Then visit the server’s IP in a browser:

# Find your server's IP
hostname -I              # LAN/internal addresses
curl -4 icanhazip.com    # public address as seen from the internet

# Then in a browser
http://your_server_ip

You should see the “Apache2 Ubuntu Default Page” — that confirms Apache is serving requests.

Step 4: Set up a virtual host

Virtual hosts let one Apache instance serve many domains. For a domain example.com:

# 1. Create the document root
sudo mkdir -p /var/www/example.com

# 2. Hand it to your user (so you can edit without sudo)
sudo chown -R $USER:$USER /var/www/example.com

# 3. Make sure it's readable by the web server group too
sudo chmod -R 755 /var/www/example.com

# 4. A sample index file
sudo tee /var/www/example.com/index.html >/dev/null <<'HTML'
<html>
  <head><title>Welcome to example.com</title></head>
  <body><h1>example.com is live</h1></body>
</html>
HTML

# 5. Create the virtual host config
sudo nano /etc/apache2/sites-available/example.com.conf

Paste this:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
# 6. Enable the new site
sudo a2ensite example.com.conf

# 7. Disable the catch-all default
sudo a2dissite 000-default.conf

# 8. Test the config
sudo apache2ctl configtest
# Syntax OK

# 9. Reload (no dropped connections)
sudo systemctl reload apache2

The site is now served — make sure your domain’s DNS A record points at the server before you hit http://example.com in a browser.

Managing Apache with systemctl

sudo systemctl start apache2       # start
sudo systemctl stop apache2        # stop
sudo systemctl restart apache2     # hard restart
sudo systemctl reload apache2      # graceful reload (preferred for config changes)
sudo systemctl enable apache2      # start at boot
sudo systemctl disable apache2     # don't start at boot

Where Apache puts its files

  • /var/www/html — default document root. Most setups serve from per-site directories like /var/www/example.com instead.
  • /etc/apache2/apache2.conf — main config. Loads everything else.
  • /etc/apache2/ports.conf — defines which ports Apache binds to (defaults 80 and 443).
  • /etc/apache2/sites-available/ — every virtual host’s config lives here. Files become “active” when symlinked into sites-enabled/ by a2ensite.
  • /etc/apache2/mods-available/ and mods-enabled/ — Apache modules; toggle with a2enmod / a2dismod.
  • /etc/apache2/conf-available/ and conf-enabled/ — config snippets that aren’t tied to a single virtual host (PHP setup, security headers); toggle with a2enconf / a2disconf.
  • /var/log/apache2/access.log — every request.
  • /var/log/apache2/error.log — every error.

Next steps

  • Add HTTPS — install Certbot (sudo apt install certbot python3-certbot-apache) and run sudo certbot --apache -d example.com.
  • Install PHP — sudo apt install php libapache2-mod-php for mod_php, or php-fpm for the more modern FastCGI setup.
  • Switch the open ports — sudo ufw delete allow 'Apache' then sudo ufw allow 'Apache Full' once HTTPS is live.

Frequently asked questions

Should I pick Apache or Nginx for a new site?

Both serve static and dynamic content competently. Apache’s .htaccess per-directory config makes it the friendlier choice when you can’t always touch the main config (shared hosting, WordPress sites maintained by non-admins). Nginx tends to be lighter under heavy concurrency. For a single VPS hosting a few sites, the difference rarely matters — pick what you know.

What’s the difference between systemctl restart and systemctl reload?

restart stops Apache fully and starts it again — every connection dies. reload tells Apache to re-read its config without dropping connections; in-flight requests complete and new ones use the new config. Use reload for config changes; restart only when you’ve installed a new module or hit a state issue.

Why is the default site at /var/www/html served before my virtual host?

Apache reads sites alphabetically. 000-default.conf sorts before any name you give your site, so without a2dissite 000-default.conf the default catches every request that doesn’t match a more specific ServerName. Disable the default once your virtual host is working.

How do I add HTTPS / SSL to a virtual host?

Install Certbot — sudo apt install certbot python3-certbot-apache — then sudo certbot --apache -d example.com -d www.example.com. Certbot reads your existing virtual host, requests a Let’s Encrypt certificate, writes a new example.com-le-ssl.conf file with the SSL config, and sets up auto-renewal. You’ll also want sudo ufw allow 'Apache Full' instead of plain 'Apache' to open 443.

Related guides

  • How to Install PHP on Ubuntu
  • How to Install MySQL on Ubuntu
  • How to Configure Nginx for a Subdirectory

References

Apache HTTP Server documentation: httpd.apache.org/docs/2.4. Ubuntu Apache documentation: ubuntu.com/server/docs/web-servers-apache. Let’s Encrypt with Certbot: certbot.eff.org/instructions.

TAGGED:ApacheconfigurationLinuxUbuntu

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Install HandBrake CLI on Linux with Flatpak How to Install HandBrake CLI on Linux (Flatpak)
Next Article Keep the first N characters of a JavaScript string with slice How to Keep Only the First N Characters of a String in JavaScript
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Display PHP errors — ini_set + php.ini configuration
Web Development

How to Display PHP Errors

7 Min Read
Switch from LiteSpeed to Apache in WHM/cPanel
Server Management

How to Switch from LiteSpeed to Apache in WHM/cPanel

4 Min Read
Install PHP on Ubuntu — terminal with apt install php command and stylized elephant icon
Web Development

How to Install PHP on Ubuntu (22.04 & 24.04): Step-by-Step Guide

9 Min Read
Reset the LiteSpeed WebAdmin Console password
Server Management

How to Reset the LiteSpeed WebAdmin Console Password

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?