VirtualHost allows you to assign different websites across domains to the same IP address. They allow easy access to a PHP application hosted on an Apache web server through a simple domain. For this reason, is very used for web developers and system administrators. In this article, I will show you how to configure an Apache virtual host on Debian 9.

0.What you need

Before you start, you must have certain requirements for everything to work perfectly.

  • Have, at least, a notion of how to use the command line interface.
  • A user who can use sudo.
  • A desire to learn. Vital to acquire the knowledge that I will give you.
  • A computer with Debian 9 installed. Obvious, isn’t it?

1. Install Apache web server

Generally, before you start installing and configuring a system, it is a good idea to perform a general system upgrade. With this, you will obtain the last security patches.

Open a terminal and run on it:

After you enter your password, the update process will begin. As a result, you will have an updated and secure system.

1.- Upgrading the system
1.- Upgrading the system

Now, you can install apache2 from the official Ubuntu repositories. Run:

2.- Installing apache2 web server
2.- Installing apache2 web server

As a result, you can now go to your browser and set the IP address of the server and you will see a page similar to this one. Open it.

http://IP_server/

3.- Apache2 deafult page
3.- Apache2 default page

Good job. Apache is running smoothly on your computer.

2.- Create web directory for each Apache virtual host

In order to create a structure of efficient directories and that the Virtual hosts do not have problems, you must create a directory for each one of them. In this case, I will only create two virtual hosts. One called “osradar1.local” and other called “osradar2.local”.

Create the folders:

4.- Creating the folders for virtual host
4.- Creating the folders for the virtual hosts

With this in mind proceeds to change the owner of them. Run,

5.- Changing the folders owner
5.- Changing the owner of the folders

Finally, change the permissions on the folders.

6.- Changing the permissions to the folders
6.- Changing the permissions to the folders

Now, create an example index.html file, to check the operation.

For the first hosts (osradar1.local) in index.html, type this:

And for the second host:

3.- Create the configuration file for each host

In this step, you must create the configuration files for each virtual host, but it’s not complicated because you can rely on the default configuration file.

In the first place, copy the default configuration file, and rename it for each virtual host.

7.- Copying the apache default configuration file
7.- Copying the apache default configuration file

Now, you must edit the files to adapt them to each virtual. For example, edit osradar1.local.conf.

In that file, you must modify ServerName, ServerAlias, ServerAdmin, and DocumentRoot.

8.- Editing Virtual host configuration file
8.- Editing Virtual host configuration file

Do the same for the other virtual host.

9.- Editing the second file
9.- Editing the second file

4. Enabling configuration files

Once the configuration files are ready, you must activate them. First, disable the default configuration file and then activate the newly created virtual hosts.

10.- Enabling new configuration file for the virtual hosts
10.- Enabling new configuration file for the virtual hosts

And it’s ready. Now let’s check that everything was successful. Restart apache2.

5.- Test the virtual hosts

In the first place, edit the file /etc/hosts and add your IP with the names of the virtual hosts.

11.- Editing hosts file<
11.- Editing hosts file

Now, go to your web browser and enter your virtual host.

12.- Checking the virtual hosts
12.- Checking the virtual hosts
13.- Checking virtual hosts
13.- Checking virtual hosts

And this is it. As you can see it’s really simple.

Tell us, how was your experience with Apache?

Please spread this article through your social networks.

Spread the love
  • 2
    Shares

PS. If you like this post please share it with your friends on the social networks using the buttons above.Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here