How to Install Apache on Ubuntu: A Step-by-Step Guide
The Apache HTTP Server is a free program that lets you host websites on your computer or a web server, and it powers a huge part of the internet. Ubuntu includes version 2.4.x by default, which you can install in just a few minutes using the terminal.
Install Apache on Ubuntu by running `sudo apt update` then `sudo apt install apache2`. Verify it’s running with `sudo systemctl status apache2`. Allow traffic on ports 80 and 443 using `sudo ufw allow ‘Apache Full’`.
Install Apache
Ubuntu includes Apache in its default software repositories, meaning installation takes a couple of commands. Open your terminal and run `sudo apt update` followed by `sudo apt install apache2`.
To install Apache, run the command below.
sudo apt update sudo apt install apache2
Once Apache is installed, it will start automatically.
To verify the service is running, use the command below.
sudo systemctl status apache2
The command should output lines similar to the one below.
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
Active: active (running) since Wed 2024-01-17 17:25:14 CST; 1min 22s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 3668 (apache2)
Tasks: 55 (limit: 2261)
Memory: 4.9M
CPU: 51ms
CGroup: /system.slice/apache2.service
├─3668 /usr/sbin/apache2 -k start
├─3670 /usr/sbin/apache2 -k start
└─3671 /usr/sbin/apache2 -k start
...Allow traffic on HTTP and HTTPS ports
Here is how to do that on Ubuntu Linux. Run the command below to open the firewall, assuming UFW is being used.
sudo ufw allow 'Apache Full'
Setup Virtual Host
Configuring Virtual Hosts Apache handles multiple websites on a single machine through virtual hosts, which separate files and settings for each domain. This capability proves helpful when running more than one site. Apache already comes with a default virtual host set up, which will handle any domain names pointing to your server's IP address.
Apache comes with one virtual host enabled by default. If domains point to your server's IP address, they'll all match the default virtual host. For a single website, upload its content to the default virtual host's directory and edit the host configuration file.
If you are hosting a single website, you can upload its content in /var/www/html and edit the virtual host configuration found in the /etc/apache2/sites-enabled/000-default.conf file.
To test a virtual host, run the command below to create a website folder called example.com in the /var/www/ directory.
sudo mkdir -p /var/www/example.com/public_html
Then, create a basic HTML index file in the directory.
sudo nano /var/www/example.com/public_html/index.html
Copy and paste the content below into the file.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to example.com</title>
</head>
<body>
<h1>Success! example.com home page!</h1>
</body>
</html>Save the file and exit.
Change the ownership of web content to the Apache user, named `www-data`, by running the command `sudo chown -R www-data:www-data /var/www/html`. This ensures Apache can read and write files in its web directory.
sudo chown -R www-data: /var/www/example.com
Next, create a virtual host file for the website. Apache vhosts files are stored in the /etc/apache2/sites-available directory.
sudo nano /etc/apache2/sites-available/example.com.conf
A very basic vhost file should resemble the one below.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>Save the file.
Next, run the command below to enable the configuration.
sudo a2ensite example.com
Test the config and ensure nothing is wrong.
sudo apachectl configtest sudo systemctl restart apache2
When all is configured correctly, you should see a test page when browsing the website.

With the service running and your virtual host configured, you are ready to build out your web projects.
Conclusion:
- Apache is a versatile and widely used open-source web server providing powerful features for web applications.
- Installing Apache on Ubuntu Linux is straightforward using the package manager, making it a convenient web hosting option.
- Configuring virtual hosts allows running multiple websites on a single server, each with separate content and domain names.
Does Ubuntu come with Apache installed?
Apache is included in Ubuntu's default package repositories, so you can install it using standard package management tools. Let's start by updating your server's local package index to make sure you're installing the latest available version.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
[…] How to install Apache on Ubuntu […]
[…] management system (CMS), can be installed on a web server to create and manage dynamic websites. Apache, a widely trusted web server software, and Ubuntu, a widespread and reliable Linux distribution, […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] How to install Apache on Ubuntu […]
[…] Install Apache HTTP server on Ubuntu […]