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

When we talk about the server of ApacheWe also talked about a popular alternative option that most websites can have. In fact, for some time now, about a third of all websites work on this server, which shows its viability.

On the other hand, it is also presented as robust and with sufficient accessibility to all developers who want to work on it. All this attraction to Apache actually 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 with which to work.

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

This is done through a process in which the visitor never realizes that the same server is working based on other websites, which creates a large branching of sites that can be expanded as long as you have the tools to do so.

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

purple cover ubuntu

What you need to know

Now, in order to start configuring your server, you first need to download Apache to your computer. This you have to do through a non-root user, and you can do it using an apt package with the 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 the “example.com” for the name of the site in question. Also, you should know that you can restart your Apache server when you think it is necessary.

Setting up a virtual host with Apache

First, we must find a directory structure that can show the data that the visitor sees when they enter the site. Every time we are going to create a directory, we have to do it through the creation of a “public_html” where all the relevant files will be, which will help with the hosting.

We can do this through the lines “$ sudo mkdir –p /var/www/example.com/public_html” followed by “$ sudo mkdir –p /var/www/example.com/public_html”.

artistic design virtual hosts

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

Keep in mind that the “$ USER” will be the user that is open as soon as the “enter” key is pressed. Likewise, you must configure the read access permissions with “$ sudo chmod -R 755 / var / www”.

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

We can do this 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 example.com virtual host is working!

”, Followed by another two lines of body and html respectively.

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

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

How useful did you find this content?

Click on a star to rate!

Average score 0 / 5. Counting of votes: 0

So far, no votes. Be the first to rate this content.

I'm sorry this content was not useful for you!

Let me improve this content!

Tell me, how can I improve this content?

Deja un comentario