Skip to content
Follow
Ubuntu Linux

How to Install Apache on Ubuntu: A Step-by-Step Guide

Richard
Written by
Richard
Jan 17, 2024 Updated Mar 19, 2026 4 min read
How to Display Seconds on Ubuntu Top Menu Clock
How to Display Seconds on Ubuntu Top Menu Clock

You install Apache on Ubuntu by using the command line and the apt package manager.

Apache HTTP Server is a popular, free, and open-source web server that you can use to host websites and web applications. It’s known for its reliability and extensive feature set, running a significant portion of the world’s web traffic.

Typically, you’ll install the latest stable version, which is commonly found within the 2.4.x series on Ubuntu systems. This process is straightforward and allows you to start serving content quickly.

⚡ Quick Answer

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

On Ubuntu and Debian systems, the Apache package and service are called apache2.

It’s included in the default Ubuntu repositories, so installing it is quite simple.

To install Apache, run the command below.

🐧Bash / Shell
sudo apt update
sudo apt install apache2

Once Apache is installed, it will start automatically.

To verify that the service is running, run the command below.

🐧Bash / Shell
sudo systemctl status apache2

The command should output lines similar to the one below.

💻Code
● 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

Apache, by default, listens on port 80 (HTTP) and 443 (HTTPS). If you need to connect to the server, you might have to open the necessary ports for communication.

Here’s how to do that on Ubuntu Linux. Run the command below to open the firewall, assuming UFW is being used.

🐧Bash / Shell
sudo ufw allow 'Apache Full'

Setup Virtual Host

Apache’s virtual host configuration directive lets you run multiple websites on a single server. Typically, a virtual host describes one website. This means multiple domain names can be hosted on a single server, with separate content for each domain.

Apache ships with one virtual host enabled by default. If domains point to your server’s IP address, they’ll all match the default virtual host. If you’re hosting a single website, you can upload its content in the default virtual host location and edit the host configuration in the Apache 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.

🐧Bash / Shell
sudo mkdir -p /var/www/example.com/public_html

Then, create a basic HTML index file in the directory.

🐧Bash / Shell
sudo nano /var/www/example.com/public_html/index.html

Copy and paste the content below into the file.

💻Code
<!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.

Next, run the command below to change the ownership of the web content to the Apache user (www-data).

🐧Bash / Shell
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.

🐧Bash / Shell
sudo nano /etc/apache2/sites-available/example.com.conf

A very basic vhost file should resemble the one below.

💻Code
<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.

🐧Bash / Shell
sudo a2ensite example.com

Test the config and ensure nothing is wrong.

🐧Bash / Shell
sudo apachectl configtest
sudo systemctl restart apache2

When all is configured correctly, you should see a test page when browsing the website.

Install Apache on Ubuntu Linux system
Install Apache on Ubuntu Linux system

That should do it!

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?

Was this helpful?
Richard

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.

📚 Related Tutorials

How to Install i-doit on Ubuntu with Apache
CMS How to Install i-doit on Ubuntu with Apache
How to Change Default Distro in Windows Subsystem for Linux
Windows How to Change Default Distro in Windows Subsystem for Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

54 Comments

Leave a Comment

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