×


Install and Configure Apache Web Server with Virtual Host on Debian 10 - Do it now ?

Apache is an extensively used open-source web server also referred to as an Apache HTTP server. It is a free cross-platform web server that is supported on various operating systems including Microsoft Windows, Linux, macOS, Solaris, and so on. 

Apache web server is highly customizable, easy to install, ships different features, and can integrate with other modules.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Open Source Software Installation tasks on Debian System.

In this context, we shall look into how to install Apache webserver on the Debian 10 system.


How to Install Apache web server on Debian 10 ?

Here, All command must run under the sudo privileges.


1. Update package repository

Open the command line application and type the following command on the terminal to make sure that all packages are updated in your system:

$ sudo apt update


2. Install Apache2

In this step, we will install the Apache web server by running the below-mentioned command in the terminal:

$ sudo apt install apache2

The system will ask you about the installation confirmation. You need to enter the 'y' and then press 'Enter' in order to continue the installation of Apache on your system.

Once the installation of the Apache web server is complete, run the following command to check the installed version:

$ apache2 -version


3. Firewall configurations

If ufw is not installed then first install it and then configure it. 

So that, allow access to port 80 on the firewall by running the below-given command:

$ sudo ufw allow 80/tcp

Now, execute the following command to view the firewall status:

$ sudo ufw status

If the status is inactive on this system then, enable it by using the following command and then, again check status:

$ sudo ufw enable


4. Verification of Apache services

Before starting the configurations, make sure that Apache services are running on your system. 

Type the following command to check apache services status:

$ sudo systemctl status apache2

If apache services are not running like the above output then, start the apache services by executing the following command and again check the status:

$ sudo systemctl start apache2

Apache services are now running on your system.


To check apache is running properly on your system or not, request a web page from the Apache server. 

To request a web page, find your IP address by executing the following command:

$ hostname -I

Now, open the browser Mozilla Firefox and type your IP address in the address bar as follows:

http://your- machine-IP-address

When you navigate the above-mentioned URL, an apache welcome page will display in your browser that represents Apache is working fine on your Debian system.


How to create virtual hosts in Apache web server?  

Here, you will learn how you can create virtual hosts through which you can host multiple websites on a single web server. 

Also, we will show you how you can set up virtual hosts in Apache web servers.


1. Create webroot directory for the specific domain

So first, we will create a 'webroot' directory using the domain 'ibmimedia.com'.

$ sudo mkdir -p /var/www/html/ibmimedia.com/

The next step is to assign the certain required permissions for ownership to this directory by using the variable name $USER.

$ sudo chown -R $USER:$USER /var/www/html/ibmimedia.com/

Assign permission for the domain as follows:

$ sudo chmod -R 755 /var/www/ibmimedia.com


2. Create an HTML web page for the website

Open one of your favorite text editors and create a file with the name 'index.html'.

$ sudo nano /var/www/html/ibmimedia.com/index.html

Now, copy and paste the following html lines of code in this file:

<html>
    <head>
        <title>Welcome to ibmimedia.com</title>
    </head>
    <body>
        <h1>Apache installation guide!</h1>
    </body>
</html>

If you are using a nano editor, press 'Ctrl + O' to save this content and then press 'Ctrl+x' to exit from the editor.


3. Make a virtual host file

Here, you will create a virtual host file for the 'ibmimedia.com' domain by using the following command:

$ sudo nano /etc/apache2/sites-available/ibmimedia.com.conf

Paste the below-mentioned lines in this file:

<VirtualHost *:80>
ServerAdmin admin@ibmimedia.com
ServerName ibmimedia.com
ServerAlias ibmimedia.com
DocumentRoot /var/www/ibmimedia.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the virtual host file by running the following command:

$ sudo a2ensite ibmimedia.com.conf

Execute the following command to disable the default site configurations:

$ sudo a2dissite 000-default.conf

Now, test for errors by using the below given command:

$ sudo apache2ctl configtest

If you may receive the error like the above, then you need to change the server name into the following locations:

$ sudo nano /etc/apache2/conf-available/servername.conf

Add the ServerName ibmimedia.com as follows and exit from the configurations.


Enable the changes by running the following command:

$ sudo a2enconf servername

Restart the apache services by executing the below-mentioned command:

$ sudo systemctl restart apache2

Now, again test the configurations by typing the following command:

$ sudo apache2ctl configtest

Now, open the browser and use this link http://ibmimedia.com in the address bar.


How to uninstall Apache Web Server ?

If you no longer need Apache web server and want to remove it along with its dependent packages from your system, run the following command on terminal.

$  sudo apt-get purge apache2


[Need to set up Apache Web Server on your Linux Server? We are available to help you. ]


Conclusion

This article covers how to perform installation and configuration of Apache web server on Debian 10.

Also, you will learn how to create virtual hosts on an Apache server and troubleshoot errors. These steps are almost the same for Ubuntu and LinuxMint distributions.

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web.


On most systems if you installed Apache with a package manager, or it came preinstalled, the Apache configuration file is located in one of these locations: /etc/apache2/httpd. conf. /etc/apache2/apache2.


Debian/Ubuntu Linux Specific Commands to Start/Stop/Restart Apache:

1. Restart Apache 2 web server, enter: # /etc/init.d/apache2 restart. $ sudo /etc/init.d/apache2 restart.

2. To stop Apache 2 web server, enter: # /etc/init.d/apache2 stop.

3. To start Apache 2 web server, enter: # /etc/init.d/apache2 start.


To check running status of LAMP stack:

1. For Ubuntu: # service apache2 status.

2. For CentOS: # /etc/init.d/httpd status.

3. For Ubuntu: # service apache2 restart.

4. For CentOS: # /etc/init.d/httpd restart.

5. You can use mysqladmin command to find out whether mysql is running or not.