Skip to main content

How to Install Apache HTTP Server on Debian

Apache HTTP Server is a popular open-source web server that is widely used to serve web pages on the internet. It is fast, reliable, and customizable, making it an excellent choice for both small and large websites. In this tutorial, we will show you how to install Apache HTTP Server on Debian in a step-by-step manner.

Prerequisites

Before we begin, make sure you have the following:

  • A Debian-based operating system
  • Root access or sudo privileges
  • Basic knowledge of the Linux command line

Step 1: Update the system

The first step is to update your system to the latest version. This can be done by running the following command:

sudo apt update && sudo apt upgrade -y

This command will update all the packages installed on your system.

Step 2: Install Apache HTTP Server

To install Apache HTTP Server, run the following command:

sudo apt install apache2 -y

This command will install Apache HTTP Server along with all its dependencies.

Step 3: Configure Apache HTTP Server

Once the installation is complete, the Apache HTTP Server should start automatically. To verify that Apache HTTP Server is running, you can run the following command:

sudo systemctl status apache2

This command will display the status of Apache HTTP Server, and you should see something like this:

● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Mon 2021-11-01 12:00:00 UTC; 1min ago
Main PID: 1234 (apache2)
Tasks: 55 (limit: 2345)
CGroup: /system.slice/apache2.service
├─1234 /usr/sbin/apache2 -k start
├─5678 /usr/sbin/apache2 -k start
└─9012 /usr/sbin/apache2 -k start

This output indicates that Apache HTTP Server is running.

Step 4: Test Apache HTTP Server

To test Apache HTTP Server, open your web browser and enter the IP address of your server. You should see the Apache default page, which confirms that Apache HTTP Server is working correctly.

Step 5: Create a Virtual Host

A virtual host is a way to host multiple websites on the same server. To create a virtual host, you need to create a new configuration file in the /etc/apache2/sites-available/ directory.

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

Replace example.com with your domain name.

Add the following content to the file:

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>

Save the file by pressing CTRL+X, then Y, and finally ENTER.

Step 6: Enable the Virtual Host

After creating the virtual host configuration file, you need to enable it by running the following command:

sudo a2ensite example.com.conf

This command will create a symbolic link to the virtual host configuration file in the /etc/apache2/sites-enabled/ directory.

Step 7: Restart Apache HTTP Server

To apply the changes, you need to restart Apache HTTP Server by running the following command:

sudo systemctl restart apache2

Step 8: Test the Virtual Host

To test the virtual host, open your web browser and enter the domain name you specified in the virtual host configuration file. You should see the content of the default page in the /var/www/example.com/public_html directory.

Conclusion

Congratulations! You have successfully installed and configured Apache HTTP Server on Debian and created a virtual host. Apache HTTP Server is a powerful and flexible web server that can handle a wide range of web applications. With this tutorial, you should be able to get started with hosting your own website on Debian. Happy hosting!