How To Configure Apache2 Virtual Hosts In Ubuntu

When we talk about the Apache server , we are also talking about a popular alternative option that most web sites may have. In fact, for some time now, about a third of all websites have been powered by 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, 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 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 on the basis of other websites, which creates a large ramification of sites that can be expanded as long as the tools for it.

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 download and configure different virtual hosts through Apache in Ubuntu . So, stay with us and keep reading carefully as we will tell you about everything you need to know about it.

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 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 ”.

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. Also, you must configure the read access permissions with “ $ sudo chmod -R 755 / var / www ”.

Now, we 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 ” <html> ” followed by ” <head> ” followed by ” <title> Welcome to example.com! </title> ” followed by two more lines of head and body, to then put “ <h1> Success! The example.com virtual host isworking! </h1> ”, 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.

 

Leave a Comment