Installing Apache HTTPD

LinuxBeginner
Practice Now

Introduction

Apache HTTP Server (often referred to simply as Apache) is widely used web server software. It played a major role in the growth of the early web and remains an important part of Linux administration.

Apache became especially influential because of its long history, broad module ecosystem, and flexible configuration model. Many Linux systems, tutorials, and legacy applications still rely on it heavily.

That historical footprint matters because in real operations work you will often inherit Apache-based systems even if newer projects choose different web servers.

You can think of a web server like a librarian:

  • The Library is your server.
  • The Books are your files (HTML pages, images, etc.).
  • The Librarian is Apache.

When a user visits your website, they are asking the librarian for a specific book. The librarian finds the file and hands it to the user.

In this lab, you will:

  1. Install Apache: Get the software onto your system.
  2. Start the Service: Turn the server on so it can handle requests.
  3. Explore the Document Root: Find where the website files are stored.
  4. Deploy a Custom Page: Create your own "Hello World" web page.

This lab is designed for complete beginners. No prior experience is required.

Install Apache HTTP Server

In this step, you will install the Apache web server software.

On Ubuntu and Debian-based systems, the Apache package is named apache2. On other distributions like CentOS or RHEL, it is often called httpd. Since this environment uses Ubuntu, we will use apache2.

Run the following command to install Apache:

As with Nginx, installing the package gives you the software and default configuration files. It does not by itself prove that the server is already running and serving requests correctly.

sudo apt install apache2 -y
  • sudo: Run the command with administrative privileges.
  • apt install: The command to install packages.
  • -y: Automatically answer "yes" to prompts.

Once the installation is complete, verify the installed version to ensure the process was successful:

apache2 -v

You should see output similar to Server version: Apache/2.4.x, confirming that Apache is installed.

Start the Apache Service

Now that Apache is installed, you need to start the service. Just installing the software does not automatically start the web server process.

This is the same installed-software versus running-service distinction you saw with other daemons. A server package can exist on disk while no process is actively listening for HTTP traffic.

Start the Apache service using the service command:

sudo service apache2 start

Now, verify that the service is running:

sudo service apache2 status

You should see a message indicating that apache2 is running.

In a production environment, you would typically configure Apache to start automatically when the server boots using systemctl enable apache2. However, in this lab environment, manually starting the service is sufficient.

Explore the Document Root

Apache needs to know where to look for your website files. This location is called the Document Root.

By default on Ubuntu, the document root is located at /var/www/html. When you installed Apache, it placed a default "It works!" HTML file in this directory.

The document root is Apache's default starting point for static content. When no special routing or application logic is involved, requests are usually resolved into files under this directory.

Navigate to the document root directory:

cd /var/www/html

List the files in the directory:

ls -l

You should see a file named index.html. This is the file that is served when you visit the web server's address.

Deploy a Custom Web Page

Now you will replace the default Apache page with your own custom message.

Since /var/www/html is owned by the root user, you need to use sudo to modify files in this directory. We will use a simple command to overwrite the existing index.html.

Run the following command to create a new index.html file with the content "Hello LabEx":

echo "Hello LabEx" | sudo tee /var/www/html/index.html
  • echo "Hello LabEx": Generates the text "Hello LabEx".
  • |: Pipes that text to the next command.
  • sudo tee ...: Writes the input it receives to the specified file, using root privileges.

Verify the file content:

cat /var/www/html/index.html

Finally, test your web server by making a request to localhost (your own computer):

curl localhost

You should see Hello LabEx in the output. This confirms that Apache is running and serving your custom page.

At that point you have verified the same full chain as with any web service: program installed, daemon running, files placed in the document root, and HTTP response reaching the client.

Summary

In this lab, you successfully installed and configured the Apache HTTP Server. You learned how to:

  • Install the apache2 package on Ubuntu.
  • Start and check the status of the Apache service.
  • Navigate to the default document root /var/www/html.
  • Replace the default index.html with your own content.

These are the first steps in web server administration. You now have a functioning web server capable of hosting static web pages.