How to Configure Apache2 Virtual Hosts in Ubuntu - Quick and Easy

Who I am
Pavel Yosifovich
@pavelyosifovich
Author and references

When we talk about the server Apache, we're also talking about a popular alternative option that most websites can have. In fact, for some time now, about a third of all websites have been powered by this server, which proves its feasibility.

On the other hand, it also comes as robust and with sufficient accessibility to all developers who want to work with it. All this attraction to Apache, in fact, lies in the fact that it is possible to host different types of domains within the same IP through a matching system, which leaves the server administrator a lot of freedom to work with.



On the other hand, each virtual host that is configured through Apache brings each visitor to a certain directory, where all the site information they want to find is stored.

This is done through a process where the visitor never realizes that the same server is on working based on other websites, which creates a large branching of sites that can be expanded as long as the tools for it.

That is why, if all of this catches your attention and you want to install Apache2 or you are simply having difficulty using this type of tool with your sites, we will show you how download and configure different virtual hosts via Apache in Ubuntu. So, stay with us and keep reading carefully as we will tell you everything you need to know about it.

What do you need to know

Now, to start setting up your server, you first need to download Apache to your computer. This you have to do via a non-root user, and you can do it using an apt package with lines " $ sudo aptupdate " followed by " $ sudo aptinstall apache2 ".



We also remind you that in the step by step in which we will tell you how you can configure your Apache server, you will have to change “example.com” for the name of the site in question. Also, you should know that you can restart your Apache server when you feel it is necessary.

Configure a virtual host with Apache

First, we need to find a directory structure that can show the data the visitor sees when they enter the site. Whenever we will create a directory, we have to do it by creating a “public_html” where all the relevant files will be, which will help with hosting.

We can do it across the lines " $ sudo mkdir –p /var/www/example.com/public_html " followed by " $ sudo mkdir –p /var/www/example.com/public_html ".

Now, we need to grant the necessary permissions to regular users, which we do with the " $ sudo chown -R $ USER: $ USER /var/www/example.com/public_html " followed by " $ sudo chown -R $ USER: $ USER /var/www/example.com/public_html ".


Note that "$ USER" will be the user who opens as soon as the "enter" key is pressed. Also, you need to configure read access permissions with " $ sudo chmod -R 755 / var / www ".

Now, we just have to start creating all the virtual host files so that the creation of them begins, which we should do after creating the creation pages.

This can be done through the codes of " " followed by " " followed by " Welcome to example.com! "Followed by two more lines of head and body, and then put" Success! The virtual host example.com works! ”, Followed by two more lines of body and html respectively.


And, in the end, the file that will start with the new hosts should look like the one where serveradmin, documentroot, errorlog, and customlog are displayed.

All this, with the necessary knowledge and code, you will be able to train your virtual host with Apache, and then only customize it respectively.


add a comment of How to Configure Apache2 Virtual Hosts in Ubuntu - Quick and Easy
Comment sent successfully! We will review it in the next few hours.