How to Install Apache Web Server on Ubuntu?

How to Install Apache Web Server on Ubuntu?

When you set up a web server on Ubuntu, a browser check can tell you whether Apache is responding. Apache is software that listens for web requests and serves content.

I’ll show you how to install Apache with apt, Ubuntu’s tool for installing software, and check its default page in a browser.

TL;DR

Install Apache from Ubuntu’s package repositories with apt, then start apache2 and request the server’s default page.

  • Run sudo apt update, then sudo apt install apache2.
  • Check the service with sudo systemctl status apache2.
  • Use http://localhost on the Ubuntu machine to check its local response.

What is Apache on Ubuntu?

Apache HTTP Server is software that listens for web requests and serves content. Ubuntu’s package is named apache2, and the packaged service is managed as apache2 through systemd.

The package includes a default site rooted at /var/www/html. Requesting it gives you a basic check before you configure a domain or add your own site files.

What you need before installing Apache

Use an Ubuntu machine with a network connection to its configured package repositories and an account allowed to run commands with sudo. The package version comes from the enabled Ubuntu repositories, so it can vary by release and updates.

  • Use an account with sudo permission to install packages and manage services.
  • For remote access, identify the firewall that controls inbound HTTP traffic.

How to install Apache on Ubuntu step by step

Install apache2 before checking its service and default response. Open a firewall rule only when other devices must reach the server.

Step 1: Refresh apt package information

Update apt’s local package information so it can use the current package metadata from your configured repositories.

sudo apt update

The update refreshes package metadata only. It does not install Apache or upgrade all installed packages.

Step 2: Install the apache2 package

Next, ask apt to install Ubuntu’s Apache package. If apt asks for confirmation, review its proposed package changes before accepting.

sudo apt install apache2

Ubuntu’s Apache tutorial and the Apache installation docs both identify apache2 as the Ubuntu package name. Apt resolves its dependencies and installs the service files.

Step 3: Start and check the service

Start Apache explicitly before checking its state with systemd. The first command changes the service state, while the second reports it.

sudo systemctl start apache2
sudo systemctl status apache2

Look for an active service state. If Apache is stopped, read the status details before editing its configuration. To start it automatically after a reboot, run sudo systemctl enable apache2.

Step 4: Open HTTP in UFW only when needed

A request to localhost stays on the Ubuntu machine and does not need an inbound firewall rule. Remote requests are different: if UFW controls this server, allow HTTP there.

sudo ufw allow http
sudo ufw status

Check the displayed rules before testing from elsewhere. A cloud network rule or another firewall may still block the connection. Our Ubuntu network configuration guide covers the network settings that affect reachability.

Step 5: Request the default page

Open http://localhost in a browser on the Ubuntu machine. For a remote check, use an address the other device can reach and confirm the required network traffic is allowed.

hostname -I

Use the address reachable from the client network, then open it as an HTTP URL. Our guide to finding an IP address on Linux explains how to identify it.

Ubuntu Apache default page shown after a web request
The Ubuntu Apache default page is a useful sign that a request reached the server. It does not confirm that a custom site or virtual host is configured.

Apache returned its packaged welcome content, but that does not confirm your domain points to this machine or that a custom site is configured.

Common Apache connection errors

A local check separates Apache from network-path failures.

What you seeWhat to check next
Apache is not activeRead the details from sudo systemctl status apache2, or use the Linux service management guide.
Localhost works, remote access failsCheck the address and firewall rules for HTTP, then review open ports on Linux.
The default page appearsApache is responding. Configure a separate site for your own content.

Ubuntu stores available site configurations under /etc/apache2/sites-available. Use this directory when you move from the default page to a domain-specific site.

Conclusion

Apache is installed once its service can return the default page. The next task is deciding which files and domain the server should serve, which is separate from the initial package installation.

Keep the default document root for a local test, or set up a virtual host for a named site. A stable LAN address may help before configuring DNS or sharing a URL. See our Ubuntu static IP guide.

sudo apache2ctl configtest

Run the configuration test after editing Apache settings and before reloading the service. The virtual-host guide covers the next step when you are ready to serve your domain.

Frequently asked questions

These answers cover the package name, the service check and the default page you may see after installation.

What is the Ubuntu package name for Apache?

The Ubuntu package is named apache2. Install it with sudo apt install apache2.

How do I check whether Apache is running on Ubuntu?

Run sudo systemctl status apache2 and inspect the service state. A browser request to http://localhost checks whether the local server returns a page.

Do I need to enable UFW to install Apache?

No. UFW rules are only needed when you want connections through that firewall. A local request to localhost does not require opening inbound HTTP.

Why does Apache show its default page?

The default site is responding. Configure and enable a virtual host with your own document root when you want Apache to serve a custom site.