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.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
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.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWhat 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.
#1 Best Overall
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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →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.
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.
Rank #2
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.
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:
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.
Rank #3
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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsChoose 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.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.
Rank #4
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:
Recommended Free Tools
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.
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.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.
Best Value
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.
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 updateagain 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 apache2only after APT can refresh package metadata successfully.
The service is inactive or failed
- Run
sudo systemctl status apache2and read the latest error. - Run
sudo apache2ctl configtestto find syntax errors in a recently edited file. - 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.
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-availableand enable only the definitions you intend to serve. - Give each production domain a dedicated document root and a precise
ServerName. - Run
apache2ctl configtestbefore 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.
Quick Recap
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.




