October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Install and Configure Apache HTTP Server on Ubuntu

A practical Ubuntu guide to installing Apache2, configuring virtual hosts, enabling HTTPS, protecting document-root permissions, and diagnosing site issues.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Apache on Ubuntu with sudo apt install apache2, then configure sites under /etc/apache2/. This guide walks through the Ubuntu package, configuration layout, a named virtual host, HTTPS, safe file permissions, and a practical troubleshooting sequence.

Install Apache2 on Ubuntu

Ubuntu’s documented package-based installation is:

sudo apt install apache2

Ubuntu packages the server as apache2; installing through APT is the standard Ubuntu route. The exact Apache version depends on your Ubuntu release and package sources, so check your system’s package information if you need that version.

Ubuntu’s guides describe configuration changes to the main files as taking effect when Apache starts or restarts. After making a change, validate the configuration before applying it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
GEEKOM Air12 Budget Mini PC Office,Intel 7505,8GB RAM(64GB Max),256GB SSD
  • ➊ [ Trusted Quality for Everyday Agentic AI ] GEEKOM equips its SSDs with reliable original-grade flash and conducts rigorous stability testing to support dependable everyday operation. This commitment to quality is backed by a 3-year warranty. Simply connect the Air12 to cloud AI services for research, writing, study support and daily productivity—no NPU or complex local setup required. Designed for students, home users, light office work and first-time buyers, the Air12 is a high-value Cloud Agentic PC for everyday tasks
  • ➋ [ Intel 7505 processor ] Powered by the Intel 7505 processor (2 cores, 4 threads, up to 3.5GHz), the GEEKOM Mini PC Air12 delivers smooth performance for everyday computing, office tasks, and home entertainment. With enhanced single-core processing, it handles daily workloads efficiently and responsively. Compact, quiet, and energy-efficient — a solid alternative to bulky desktops.
  • ➌ [440lbs(200kg) Pressure Rated Metal Frame for Demanding Environments] Unlike the Plastic Shells You’ll Find on Most Mini PCs, geekom Mini Air12 features a triple-reinforced ABS+PC shell, precision-crafted metal frame and baseplate—engineered to withstand up to 440 lbs of pressure for the perfect balance of strength and thermal efficiency. Tool-free upgrades, shock-absorbing feet, and a 3D antenna deliver true durability
  • ➍ [Dual-Channel RAM & NVMe SSD Expandability] Ships with 8GB DDR4 RAM and a 256GB NVMe SSD for smooth everyday performance. Dual memory slots and dual storage slots give you the flexibility to upgrade to 64GB RAM and 2TB SSD, so your system can adapt as your workload grows. Enjoy faster load times, smoother multitasking, and long-term reliability.
  • ➎ [Triple 4K Displays for Maximum Productivity] Connect up to three 4K monitors via HDMI 2.0, Mini DisplayPort 1.4, and USB-C — ideal for stock trading dashboards, multi-tab research, office document editing, and light spreadsheet work. WiFi 6 and Bluetooth with high-gain antenna ensure stable wireless connections throughout your workspace. 5x USB ports and a full-size SD card reader provide quick access to peripherals and camera files — no adapters required.
sudo apachectl configtest

A successful test reports Syntax OK. Then restart the service when the change requires it:

sudo systemctl restart apache2.service

Understand Ubuntu’s Apache configuration tree

The main global configuration file is /etc/apache2/apache2.conf. Modern Ubuntu uses the /etc/apache2/ tree rather than the old httpd.conf arrangement as its default layout.

Path Purpose
/etc/apache2/apache2.conf Main global configuration.
/etc/apache2/sites-available/ Virtual-host configuration files that are available to enable.
/etc/apache2/sites-enabled/ Links to site configurations currently enabled.
/etc/apache2/mods-available/ and /etc/apache2/mods-enabled/ Module configurations, separated into available and enabled sets.
/etc/apache2/conf-available/ and /etc/apache2/conf-enabled/ General configuration snippets, separated into available and enabled sets.
/etc/apache2/ports.conf Listener directives, including the documented default listener on port 80.

Use a2ensite and a2dissite to enable or disable sites rather than treating the two site directories as interchangeable. The default site file is /etc/apache2/sites-available/000-default.conf, and its documented document root is /var/www/html. See Ubuntu’s Apache2 installation guide for the configuration layout.

Choose the site and listener setup

One site or multiple hostnames

A single default virtual host can serve one site. If the machine serves multiple hostnames, create separate name-based virtual hosts so each hostname can map to its own settings and document root. This makes the mapping and ongoing maintenance clearer; use distinct site configurations when that organization is useful for your deployment. Apache’s Virtual Host documentation explains the model and how Apache selects a host.

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

Public-facing or loopback-only listener

Listener configuration belongs in /etc/apache2/ports.conf. An unspecified address listens on the machine’s assigned addresses; binding to 127.0.0.1:80 restricts access to the local machine. Choose based on intended reachability: a public site needs an appropriate externally reachable listener and network/firewall configuration, while a service intended to be reached only through a local reverse proxy may use loopback. A listener determines where Apache accepts connections, not which files it serves.

Create and enable a named virtual host

For an example hostname of example.com, create the document-root directory and a site configuration. Replace the example hostname and paths with values for your site.

  1. Create the site directory:

    sudo mkdir -p /var/www/example.com
  2. Create /etc/apache2/sites-available/mysite.conf with a virtual-host definition like this:

    <VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com
    
        <Directory /var/www/example.com>
            Require all granted
        </Directory>
    </VirtualHost>

    Set ServerName to the primary hostname and include ServerAlias only for additional hostnames this site should answer to. DocumentRoot must point to the directory containing the site files. The directory rule allows requests to that directory; ensure the filesystem permissions also allow Apache to read it.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Place your site content in the document root and check that Apache can read the directory and files.

  4. Enable the site using its filename without the .conf suffix, test the configuration, and restart Apache:

    sudo a2ensite mysite
    sudo apachectl configtest
    sudo systemctl restart apache2.service

Ubuntu’s Apache2 settings guide documents site configuration and activation. Requests whose hostname does not match a configured ServerName or alias are handled by the default virtual host, which acts as the fallback.

To disable the example site while troubleshooting, run:

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.
sudo a2dissite mysite
sudo systemctl restart apache2.service

Apache’s DocumentRoot controls the content directory; listener settings control network reachability. Request logging is separate: Ubuntu documents /var/log/apache2/access.log as the default access log. For directory requests, Apache checks configured DirectoryIndex filenames, including index.html in Ubuntu’s documented default list. If no index file exists, behavior depends on directory options and permissions; do not enable directory listings as a default.

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

Enable HTTPS

HTTPS requires the SSL module, an enabled TLS virtual host, and a certificate and private key configured for that site. Ubuntu documents the default SSL site as a starting point:

  1. Enable the SSL module:

    sudo a2enmod ssl
  2. Enable Ubuntu’s default SSL site:

    sudo a2ensite default-ssl
  3. Configure the TLS virtual host’s SSLCertificateFile and SSLCertificateKeyFile directives with paths to the certificate and matching private key for your site.

  4. Test and restart:

    sudo apachectl configtest
    sudo systemctl restart apache2.service

The certificate and key generated by the ssl-cert package are suitable for testing, not as a replacement for a certificate specific to the site or server. The configured paths must point to the certificate and key Apache is meant to use. Ubuntu’s Apache2 modules guide covers SSL setup and certificate guidance.

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

Redirect HTTP visitors to HTTPS

Only add the redirect after the HTTPS virtual host and certificate are working. Apache 2.4 documents a dedicated port-80 virtual host with a permanent redirect as the preferred approach in the described situation. For example, the HTTP virtual host can contain:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/
</VirtualHost>

Use the hostname that should be canonical for your site, and ensure any aliases are handled intentionally. Apache’s redirecting and remapping documentation discusses this approach.

Set document-root permissions safely

Apache’s worker process runs as www-data. Ubuntu’s warning is explicit: “The apache2 daemon will run as the www-data user, which has a corresponding www-data group. These should not be granted write access to the document root, as this would mean that vulnerabilities in Apache or the applications it is serving would allow attackers to overwrite the served content.” — Ubuntu Server documentation, “How to use Apache2 modules.”

Keep the web server account able to read served files without granting it write access to the document root. If multiple trusted editors need to update files, Ubuntu demonstrates using a separate shared group rather than making www-data the writer. Adapt ownership and permissions to the deployment; broad recursive permission changes can alter an existing production site’s access model.

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

Troubleshoot a site that does not respond as expected

  1. Confirm the site file is in sites-available/ and enabled in sites-enabled/. Enable it with sudo a2ensite mysite if needed, then test and restart.

  2. Compare the request’s hostname, path, and port with the site’s ServerName, ServerAlias, DocumentRoot, and the listener in ports.conf.

  3. Inspect Apache’s parsed virtual-host map with:

    sudo apachectl -S

    This can reveal which virtual host Apache associates with a hostname and which one is the fallback. If a site conflict is responsible, disable the conflicting site with a2dissite and restart.

  4. Check the site’s configured logs. The documented default access log is /var/log/apache2/access.log; a site may have its own configured log paths.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  5. For HTTPS, check that the SSL module and TLS site are enabled and that the certificate and key paths in that site’s configuration are correct.

For exact package details and release-specific behavior, consult the documentation for your Ubuntu release and its installed Apache package.

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 *

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.