How To Install the Apache Web Server on Debian 11?

Apache is an open-source web server that’s available for Linux servers free of charge. Installing an Apache web server on Linux is a straightforward process. In this article, we will install Apache Web Server Debian 11 (Bullseye).

Steps to Install Apache Web Server in Linux

Step 1: Update Your System

sudo apt update && sudo apt upgrade

Updating system to latest packages

Step 2: Install Apache Web Server

sudo apt install apache2 -y

installing Apache Web Server

Step 3: Enable the Services

sudo systemctl enable apache2

enabling system services for Apache Web Server

Step 4: Test the Server by Hosting Simple Website

First, we will create a directory for our test website using following command.

sudo mkdir /var/www/html/test_website/
  • Now we will add index.html for our test website along with some testing code using following command.
echo '
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>GFG</h1>
<p>This is a test working on Debian</p>
</body>
</html>' | sudo tee /var/www/html//index.html
  • Now we will add configuration file using following command
sudo gedit /etc/apache2/sites-available/test_website.conf 
  • and paste following config to text editor window and save it.
<VirtualHost *:80>
DocumentRoot /var/www/html/test_website
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/test_website_error.log
CustomLog ${APACHE_LOG_DIR}/test_website_access.log combined
</VirtualHost>

saving configuration

  • Once we created the required config file and test website, we will need to own the Apache website directory for permissions.
  • We will use chmod command as follows:
sudo chmod a+wr /var/www/html/ -R

Step 5: Enable the site

After creating config file, we need to enable the site. We use the a2ensite command followed by the name of site configuration file. This creates a symbolic link from the sites-available directory to the sites-enabled directory, effectively enabling the site.

syntax:

 sudo a2ensite <site_config>
sudo a2ensite test_website.conf 
  • Now we will need to restart apache2 using systemctl reload command.
sudo systemctl reload apache2
  • Now you can see locally hosted website on localhost.
http://localhost

testing website

If the above mentioned steps performed correctly, Apache Web Server will run successfully! However, If it didn’t work, then you can uninstall Apache Web Sever and can start installation again.

Steps to Uninstall Apache Web Server

  • You can completely remove Apache Web Server using apt purge command as follows
sudo apt purge apache2 -y
  • Hence we have successfully uninstalled Apache Web Server in Debian 11!

Uninstalling Apache Web Server

Conclusion

In this article, we have installed and configured the Apache Web Server on Debian 11. We have outlined the fundamental steps, encompassing updating package lists, installing the software, verifying its operation, and hosting test website. So install Apache Web Server on your Linux now!

FAQs – How to install Apache Web Server on Debian 11?

1. What is Apache, and why is it used?

Apache HTTP Server, commonly referred to as Apache, is a free and open-source web server software that enables you to host websites and web applications on your Linux system. It’s widely popular due to its reliability, security, and extensive customization options.

2. What are virtual hosts, and when are they used?

Virtual hosts allow you to host multiple websites on a single server using the same Apache installation. Each virtual host is configured with its own document root directory and server name, enabling you to manage different websites independently.

3. What are some best practices for managing multiple websites with Apache?

To manage multiple websites with Apache, Following are some best practices:

  • Use descriptive names: Choose clear and informative names for your virtual hosts to improve organization.
  • Document your configuration: Maintain clear documentation of your virtual host configurations for easy reference and maintenance.
  • Utilize version control: Consider using version control systems like Git to manage your virtual host configuration files and track changes.