DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
VGSOURCES
Get listed

ApachePATCH 2026.10.15

How to Install the Apache Web Server on Ubuntu

By VGSources Team 9 min read

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

Install Apache on an Ubuntu Server with two commands: refresh Ubuntu’s package index, then install the apache2 package. When installation finishes, browse to the server’s IP address; the default Apache page confirms that the web server is installed and serving requests.

This guide covers the complete first setup: opening the firewall safely, checking the service, locating the document root and configuration files, and creating a named virtual host for a custom domain.

As an Amazon Associate I earn from qualifying purchases.

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.

What you need before installing Apache

The procedure assumes an Ubuntu Server that you can reach over SSH and an account allowed to run commands with sudo. You also need the server’s reachable IP address for the first browser test. If a firewall is active, its policy must permit the kind of web traffic you intend to serve.

  • An Ubuntu Server installation with SSH access.
  • An account with sudo privileges.
  • The server’s IP address.
  • A plan for HTTP, HTTPS, or both if UFW is enabled.

Apache is installed from Ubuntu’s repositories. Refreshing package metadata first ensures that apt is working from the current index available to that server.

Install Apache2 from Ubuntu’s repositories

  1. Connect to the server over SSH.

    ssh your-user@server-ip

    Replace your-user and server-ip with the account and address for your server.

  2. Refresh the package index.

    sudo apt update
  3. Install Ubuntu’s Apache package.

    sudo apt install apache2

    Accept the package installation prompt when apt asks for confirmation. The package is Ubuntu’s Apache2 build and includes the service and its standard configuration layout.

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

Canonical’s Ubuntu documentation describes the sequence this way: “To install Apache2, first refresh the package index, then install the package.” Do not skip apt update merely because the server was installed recently; package indexes can become stale independently of the operating-system installation date.

Verify that Apache is installed and serving requests

Check the systemd service

Use systemd to inspect the Apache service after installation:

sudo systemctl status apache2.service

The status view shows whether the service is active and includes recent log messages. If it is not running, start it with:

sudo systemctl start apache2.service

To make Apache start automatically when Ubuntu boots, enable the service:

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

Installation normally starts the service, but checking explicitly distinguishes a completed package install from a server that is actually listening for requests.

Open the default page

From a computer that can reach the server, enter its IP address in a browser, for example http://203.0.113.10/. Ubuntu’s tutorial says that entering the web server’s IP address and seeing the default Apache page confirms that the required packages are installed and the server is serving requests.

If the browser displays the default page, Apache is responding through the default site and the default document root is available. A browser timeout, connection refusal, or an unexpected site requires the checks in the troubleshooting section rather than a second installation attempt.

Allow web traffic through Ubuntu’s firewall

UFW is Ubuntu’s default firewall configuration tool. A running Apache service can still be unreachable when the firewall blocks its listening traffic. Before changing policy, preview an HTTP rule without applying it:

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

The dry run lets you inspect the rule that would be created. If HTTP is appropriate for this server’s exposure, apply the corresponding policy:

sudo ufw allow http

For a site intended to receive encrypted web traffic, apply the HTTPS policy as well:

sudo ufw allow https

Choose the exposure that matches the service you are actually publishing. HTTP and HTTPS are separate firewall policies; previewing a rule does not open the port, while the non-dry-run command changes UFW’s active policy. If UFW is not active, these commands are not required for local Apache operation, but another network firewall or cloud security policy may still control reachability.

Know Apache’s Ubuntu file layout

Ubuntu organizes Apache below /etc/apache2/. This differs from distributions that commonly center their configuration on an httpd.conf file. On modern Ubuntu releases, apache2.conf is the main configuration file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Path Purpose
/var/www/html Default document root. Files placed here are served by Ubuntu’s default site.
/etc/apache2/apache2.conf Main Apache configuration file used by Ubuntu’s layout.
/etc/apache2/ports.conf Controls the ports on which Apache listens.
/etc/apache2/sites-available/ Stores virtual-host definition files, whether or not they are currently enabled.
/etc/apache2/sites-enabled/ Contains links for the site definitions Apache should load.

The separation between sites-available and sites-enabled lets you keep a site definition on disk while deciding whether Apache should load it. Use the Apache helper commands to change that enabled set instead of manually editing links.

Find the default document root

The default site serves content from /var/www/html. To test it without changing the site definition, create or edit an HTML file in that directory, then request the server’s IP address again. The URL path maps beneath the document root: a file named index.html is the usual page returned for the root path.

Keep custom sites in their own document-root directories when you move beyond a single site. This prevents files for unrelated domains from being mixed in the default directory and makes each virtual-host definition easier to understand.

Default site or named virtual hosts?

A single default site is enough when one server address should always return one website. Named virtual hosts are the appropriate structure when several domains share one Apache instance or when you want an explicit mapping between a domain and a directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision point Default site Named virtual host
Configuration isolation Uses the existing default site definition and the shared default document root. Uses a separate file in sites-available for each site.
Domain routing Primarily serves the default response for the address. Routes requests using ServerName and, when needed, ServerAlias.
Document root /var/www/html. A DocumentRoot chosen for that site, such as /var/www/mynewsite.
Applying changes Changes to the site configuration require a reload or restart. Enabling, disabling, or editing the host also requires a reload or restart.

Create an Apache virtual host on Ubuntu

1. Create the site’s document directory

Choose a directory that will contain the files for the new site. The path must match the DocumentRoot in the virtual-host file. For the example below, the directory is /var/www/mynewsite:

sudo mkdir -p /var/www/mynewsite

Add the site’s HTML files to that directory. A minimal test page can be created with an editor, for example:

sudo nano /var/www/mynewsite/index.html

Save a simple page, then close the editor. The exact page content is not important for the routing test; a distinctive heading makes it clear that Apache selected the new document root rather than the default one.

2. Write a site definition in sites-available

Create a file whose name identifies the site:

sudo nano /etc/apache2/sites-available/mynewsite.conf

Set a ServerName that matches the domain clients will request and a DocumentRoot that points to the directory you created:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/mynewsite
</VirtualHost>

Replace example.com with the domain assigned to your site and replace the document-root path if you selected another directory. ServerAlias is optional; include it only for additional names that should reach the same site. The host declaration above describes HTTP on port 80. Your DNS or local name-resolution setup must point the name to this server before a normal domain request can reach it.

3. Enable the virtual host

Enabling a site creates the enabled-site link that Ubuntu’s Apache layout expects:

sudo a2ensite mynewsite

The argument corresponds to the site definition’s name. If the file is mynewsite.conf, use mynewsite with a2ensite, as shown.

4. Apply the configuration

Restart Apache after enabling the site:

sudo systemctl restart apache2.service

A reload can be used when you want Apache to reread configuration without a full process restart:

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

If a change does not take effect after a reload, use the documented restart command and then check the service status. Always make one configuration change at a time while setting up a new host so that a failure can be traced to the file you just edited.

5. Test the named site

Request the configured domain in a browser. The distinctive page in /var/www/mynewsite should appear. If the server’s IP still shows the default page, the request may not contain the Host name required for virtual-host selection, or the new site may not be enabled. Test with the domain that matches ServerName or one of its aliases.

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

Disable a virtual host while troubleshooting

To stop Apache from loading a site definition without deleting the file, disable it with:

sudo a2dissite mynewsite
sudo systemctl restart apache2.service

The file remains in /etc/apache2/sites-available/, so you can correct it and enable it again later:

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

This is useful when a newly added host appears to interfere with the default site or another known-good host. Keep the disable and restart together so the running Apache process reflects the enabled-site directory.

Troubleshoot the most common installation failures

The package command cannot refresh its index

If sudo apt update reports repository or connectivity errors, resolve those errors before retrying sudo apt install apache2. The installation command depends on package metadata and repository access; repeatedly running the install command does not repair a failed update.

The service is installed but not running

Run:

sudo systemctl status apache2.service

Read the recent status output, then try:

sudo systemctl start apache2.service

If it stops again, make a note of the message shown by systemd before changing files. A configuration mistake introduced during virtual-host setup should be isolated by disabling the new site and restarting Apache.

The browser times out

First distinguish a service problem from a network-policy problem. Check the Apache service locally, then review UFW. Preview the HTTP rule with:

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

If the policy is appropriate, apply it with sudo ufw allow http. For encrypted traffic, apply the HTTPS policy separately. A browser outside the server’s network may also be subject to an upstream firewall or cloud security rule that is not controlled by Apache.

The browser shows the wrong site

Confirm that the request uses the domain in ServerName or ServerAlias, that the site was enabled with a2ensite, and that Apache was reloaded or restarted afterward. Check the DocumentRoot spelling and place a clearly identifiable test file in that directory. If necessary, disable the new site with a2dissite and restart to return to the known default configuration.

You edited the wrong configuration location

On Ubuntu, site definitions belong in /etc/apache2/sites-available/ and enabled definitions appear in /etc/apache2/sites-enabled/. Do not assume that a distribution using a historical httpd.conf-centric layout has the same paths. For Ubuntu, inspect apache2.conf, ports.conf, and the site directories under /etc/apache2/.

A repeatable setup checklist

  1. Connect to the Ubuntu Server over SSH.
  2. Run sudo apt update.
  3. Run sudo apt install apache2.
  4. Check sudo systemctl status apache2.service.
  5. Open the server IP address and confirm the default Apache page.
  6. If UFW is active, preview and then apply the HTTP or HTTPS policy required by the site.
  7. For a custom domain, create a document directory and a file in /etc/apache2/sites-available/.
  8. Set ServerName and DocumentRoot, then enable the file with sudo a2ensite mynewsite.
  9. Reload or restart Apache and request the configured domain.
  10. If the host causes problems, disable it with sudo a2dissite mynewsite and restart while you correct the definition.

What a successful installation looks like

A basic installation is complete when the apache2 package is installed, the Apache service is active, and a browser can retrieve Ubuntu’s default page from the server’s IP address. A named-site installation adds three more checks: its file is stored under sites-available, it is enabled in sites-enabled through a2ensite, and a request using the configured name returns content from the declared DocumentRoot.

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.

Quick Recap

SaleBestseller No. 3
Bestseller No. 4
Bestseller No. 5

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.

Apacheapache2Linux serverUbuntuvirtual hostweb server

Leave a reply

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

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

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.