Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk11 min

How to Install and Configure the Apache Web Server on Ubuntu

A complete Ubuntu Apache installation guide covering apt commands, service checks, UFW firewall rules, document roots, virtual hosts, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On an Ubuntu Server with SSH access, install Apache with sudo apt update followed by sudo apt install apache2. Confirm the service by opening the server IP in a browser, then use Ubuntu’s /etc/apache2/ layout to manage the default site or create named virtual hosts.

This guide covers installation, service checks, UFW firewall exposure, document roots, virtual-host setup, configuration changes, and the failure checks that help you recover safely.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What you install and what Ubuntu configures

Ubuntu packages the Apache HTTP Server as apache2. The package installs the daemon, its supporting modules, the default site, and the Ubuntu-specific configuration tree. A normal installation gives you a working default site before you create any custom domain configuration.

  • Package: apache2, installed from Ubuntu’s configured repositories.
  • Default document root: /var/www/html.
  • Configuration root: /etc/apache2/.
  • Main configuration: /etc/apache2/apache2.conf.
  • Listening-port configuration: /etc/apache2/ports.conf.
  • Available sites: /etc/apache2/sites-available/.
  • Enabled sites: /etc/apache2/sites-enabled/, which contains links to the enabled site definitions.

Ubuntu’s layout is not the same as the historical httpd.conf-centered arrangement used by some other distributions. On current Ubuntu releases, start with apache2.conf and the sites-available and sites-enabled directories.

Before you begin

Use an Ubuntu Server account with administrative access

The official procedure assumes an Ubuntu Server that you can reach over SSH. Your login needs permission to run commands with sudo. If the machine is a cloud instance, record its public or private IP address according to where clients will connect.

Decide how the server will be reached

You can begin with the default site and an IP address, or plan for one or more DNS names. A single site is useful for a quick test. Named virtual hosts are the better structure when several domains or applications will share one Apache installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check network policy before testing

Apache can be running locally while outside clients are blocked by a firewall, cloud security group, router, or upstream provider. Ubuntu identifies Uncomplicated Firewall (UFW) as its default firewall configuration tool. Determine whether UFW is active before deciding which web ports to expose.

Install Apache on Ubuntu

1. Refresh the package index

Refresh package metadata before installing so APT can resolve the current Apache package available to your Ubuntu release.

sudo apt update

Successful output ends without an error from a repository. Warnings about an unreachable third-party repository should be investigated, because they can prevent a complete installation even when the Apache package itself is available.

2. Install the Apache2 package

sudo apt install apache2

Accept the installation prompt when APT asks for confirmation. Ubuntu installs the required packages and creates the default Apache configuration. The command may also start the service as part of package setup; verify its actual state instead of assuming that it is serving traffic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Test the default page

Find the server’s reachable IP address and enter it in a browser from a client that can access that network. Ubuntu’s tutorial uses the IP-address test: the default Apache page confirms that the package is installed and responding to HTTP requests. If the browser cannot connect, continue with the service and firewall checks below rather than reinstalling immediately.

Check whether Apache is running

Inspect the systemd service

Use systemd to see whether the Apache service is active and to read recent status messages.

sudo systemctl status apache2

Look for an active (running) state. The status view also shows the most recent process messages, the unit name, and whether systemd considers the service failed. Press q to leave the status display.

Ask for a short state result

sudo systemctl is-active apache2

This returns a concise state such as active or inactive, which is convenient in scripts or when you need an unambiguous result.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test locally from the server

A local request separates Apache problems from external routing and firewall problems. If a command-line HTTP client is installed, request the loopback address and inspect the response. A successful local response while a remote browser fails points toward UFW, a cloud firewall, DNS, or another network boundary rather than the Apache process itself.

Allow web traffic through UFW

Preview an HTTP rule first

If UFW is active, preview the HTTP policy before changing it:

sudo ufw --dry-run allow http

The dry run shows what UFW would change without applying the rule. Confirm that the rule matches the exposure you intend. Opening HTTP makes the service reachable on its standard unencrypted web port; it does not provide HTTPS encryption.

Apply the policy you actually need

To apply the same HTTP rule after reviewing the preview, remove the dry-run option:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo ufw allow http

For an HTTPS-only deployment, apply the HTTPS policy appropriate to your server and certificate setup instead of exposing plain HTTP unnecessarily. If you need both protocols during a migration or redirect phase, document that choice and remove the unneeded rule later.

Remember firewalls outside Ubuntu

UFW is only one control point. A hosting provider’s security group, a corporate firewall, a home router, or a network access-control list can still block the same port. Test from a client on the intended network after changing UFW. Do not disable the firewall wholesale just to test Apache; identify which layer is refusing the connection.

Understand Ubuntu’s Apache files

The main configuration and ports

/etc/apache2/apache2.conf is the main Ubuntu Apache configuration file. /etc/apache2/ports.conf defines the ports on which Apache listens. A virtual host can match a request only after traffic reaches a listening port, so a correct site file cannot compensate for a closed firewall or a port Apache is not listening on.

Available versus enabled sites

Place site definitions in /etc/apache2/sites-available/. They do nothing until enabled. Enabling a site creates the corresponding link in /etc/apache2/sites-enabled/, where Apache’s configuration includes it. This separation lets you prepare a configuration without serving it, switch sites on or off without deleting files, and keep a rollback copy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Modules and other configuration directories

Ubuntu also provides directories for modules and other configuration fragments below /etc/apache2/. You do not need to edit those areas for a basic installation or a simple virtual host. Keep site-specific directives in the site file whenever possible so the purpose and rollback path remain clear.

Find and use the default document root

Where the default page is served from

The default site serves files from /var/www/html. A file placed there becomes part of the content returned by the default virtual host, subject to the active Apache configuration.

ls -la /var/www/html

The directory normally contains Ubuntu’s introductory page immediately after installation. Replace or supplement that page only after saving a copy if you may need it for diagnostics.

Publish a simple test file

For a controlled test, create a small HTML file in the document root with administrative privileges, then request the server IP again. Keep the test content recognizable so you can distinguish it from a cached response. If the old page remains, check that the browser is reaching the expected IP and that a different enabled site is not answering the request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a separate root for a real site

For a named site, use a dedicated directory such as /var/www/example-site rather than mixing files for several domains in /var/www/html. Separate roots make backups, permissions, deployment, and eventual removal less error-prone. Set the directory path in the site definition and ensure the Apache process can read the files.

Create an Apache virtual host

A virtual host maps incoming requests to a site configuration. The important identifiers are ServerName, any optional ServerAlias values, and DocumentRoot. The client’s requested host name must match the names you configure, and DNS or a local name-resolution entry must point that name to the Ubuntu server.

1. Create the site directory

sudo mkdir -p /var/www/example-site
sudo nano /var/www/example-site/index.html

Put a distinctive test heading in index.html. Use your preferred editor; the important result is a readable file in the directory that will become the site’s document root.

2. Create a site definition

Create a file in /etc/apache2/sites-available/. The filename is an administrative label, so choose one that identifies the domain or application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo nano /etc/apache2/sites-available/example-site.conf

A minimal HTTP virtual host can look like this:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example-site

    <Directory /var/www/example-site>
        Require all granted
    </Directory>
</VirtualHost>

Replace example.com, the alias, and the directory with your own values. ServerAlias is optional; include only names that should serve the same content. Keep the opening and closing tags balanced. A typo in a directive or path can prevent Apache from reloading.

3. Enable the site

sudo a2ensite example-site

Use the filename without the .conf suffix when invoking a2ensite. The command enables the definition by placing its link in /etc/apache2/sites-enabled/`. If the command reports that the site is already enabled, do not create a second copy of the same link.

4. Check the configuration before applying it

sudo apache2ctl configtest

Proceed only when the result reports a successful syntax check. A failed check identifies a configuration problem that should be corrected before restarting or reloading the service. This step prevents a new site file from taking down an otherwise working configuration.

5. Reload or restart Apache

Apply the enabled configuration with a reload when the service is healthy:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo systemctl reload apache2.service

A reload asks Apache to reread configuration while keeping existing workers where possible. If you need to follow the installation sequence exactly, or if a reload is not available in the current state, restart the service:

sudo systemctl restart apache2.service

After either operation, check the service status and request the configured host name. A browser pointed only at the IP may select a different default host, so test with the actual domain name once DNS or local name resolution is ready.

6. Disable a site during troubleshooting

To remove a virtual host from the active configuration without deleting its file:

sudo a2dissite example-site
sudo systemctl restart apache2.service

Run a configuration test before restarting if you have edited other files. Disabling the site lets you determine whether it is responsible for a failure while preserving the definition for correction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Default site or named virtual hosts?

Concern Default site Named virtual host
Configuration location Ubuntu’s preinstalled definition, normally in sites-available and enabled by default A separate file you create in /etc/apache2/sites-available/, then enable
Request routing Acts as the fallback site when no more specific host match is selected Routes by ServerName and optional ServerAlias
Document root /var/www/html A dedicated path such as /var/www/example-site
Isolation Several projects can end up mixed in one root unless you impose your own structure Each domain or application can have its own root and file
Applying changes Use a reload or restart after configuration edits Enable or disable with a2ensite or a2dissite, then reload or restart

Keep the default site for a first connectivity test or a deliberate fallback. Move to named virtual hosts when a domain needs its own content, logs, deployment process, or future TLS policy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Start, stop, restart, and reload Apache safely

Start a stopped service

sudo systemctl start apache2.service

Use this when the package is installed but the service is inactive. Follow it with sudo systemctl status apache2 so you can see whether startup succeeded.

Stop the service deliberately

sudo systemctl stop apache2.service

Stopping Apache makes every site unavailable until you start it again. Use this for planned maintenance, not as a first response to a single broken virtual host.

Restart after a disruptive change

sudo systemctl restart apache2.service

A restart stops and starts the service. It is appropriate when the service has entered a bad state or when you need the complete process tree recreated, but it causes a brief interruption for active clients.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload after a configuration-only change

sudo systemctl reload apache2.service

Validate the configuration first. A reload is generally the less disruptive way to apply a corrected virtual-host file while leaving the service running.

Troubleshoot common installation and access failures

The package will not install

  • Run sudo apt update again and read repository errors rather than ignoring them.
  • Confirm the machine has working DNS and outbound access to its configured Ubuntu repositories.
  • Retry sudo apt install apache2 only after APT can refresh package metadata successfully.

The service is inactive or failed

  1. Run sudo systemctl status apache2 and read the latest error.
  2. Run sudo apache2ctl configtest to find syntax errors in a recently edited file.
  3. Correct the named directive or path, run the syntax test again, and then reload or restart.

Do not repeatedly restart a service that fails immediately; the status output and configuration test are more useful than another identical restart.

The browser times out from another machine

  • Check that Apache is active locally.
  • Request the site from the Ubuntu host itself to separate application failure from network failure.
  • Preview and apply the needed UFW HTTP or HTTPS policy.
  • Check provider-level security rules, routers, and network ACLs outside Ubuntu.
  • Verify that the browser is using the correct IP address and port.

The browser shows the wrong site

Confirm that the requested host name matches ServerName or ServerAlias, that the intended site is enabled, and that its DocumentRoot contains the expected file. An IP-only request can select the default site instead of the named virtual host. If you recently changed DNS, test the authoritative destination and allow for resolver caching.

Apache serves a directory without your file

Check the exact path in DocumentRoot, the spelling and capitalization of the requested filename, and the permissions that allow Apache to read the directory and files. A successful syntax test does not prove that the content path contains the file you expect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disabling a site appears to change nothing

Make sure a2dissite received the enabled site’s label, not an unrelated filename, and then reload or restart Apache. Check the enabled directory to see which site links remain. If the request is still answered, another enabled virtual host or the default site may be the one responding.

A practical deployment checklist

  • Refresh APT metadata, then install apache2.
  • Open the server IP and verify Ubuntu’s default page before making custom changes.
  • Record the active service state with systemctl status apache2.
  • Confirm whether UFW is active and preview the required HTTP or HTTPS rule.
  • Keep site files in sites-available and enable only the definitions you intend to serve.
  • Give each production domain a dedicated document root and a precise ServerName.
  • Run apache2ctl configtest before every reload or restart caused by a configuration edit.
  • Use reload for routine configuration changes and restart only when the service state or change requires it.
  • Test from both the Ubuntu host and an external client so local service health is not confused with network reachability.

With those checks in place, Apache’s Ubuntu workflow is predictable: APT installs the package, /var/www/html proves the first response, UFW controls exposure, and the sites-available/sites-enabled pattern lets you add or remove named virtual hosts without losing their definitions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.