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. Ubuntu includes version 2.4.x by default, which installs in 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
To install Apache on Ubuntu, open your terminal and run the commands sudo apt update and sudo apt install apache2 to download and set up the web server automatically through the default software repositories.
To install Apache, run the command below.
sudo apt update sudo apt install apache2
Once Apache installs, it starts automatically.
To verify the service runs, use the command below.
sudo systemctl status apache2
The command outputs 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
To let people connect to your website, open the correct ports in your firewall (which Apache uses for web traffic).
Here is how to do that on Ubuntu Linux. Run the command below to open the firewall, assuming UFW is active.
sudo ufw allow 'Apache Full'
Setup Virtual Host
Virtual hosts let you run multiple websites on a single Ubuntu machine by using individual configuration files to separate the files and settings for each domain name.
Apache comes with one virtual host enabled by default. If domains point to your server's IP address, they 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 host a single website, 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 reads and writes 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 reside in the /etc/apache2/sites-available directory.
sudo nano /etc/apache2/sites-available/example.com.conf
A basic vhost file resembles 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 configured correctly, you see a test page when browsing the website.

With the service running and your virtual host configured, 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. Start by updating your server's local package index to ensure you install 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 […]