20 septiembre, 2024

How to create Apache virtual host in Ubuntu?

Do you want to know how to create virtual host Apache on Ubuntu? If the answer is yes, you should continue reading this article. This should be fundamental knowledge for all people who are in the IT sector, Well, virtual accommodation can make your life easier, in terms of security, space and efficiency.. So, below, we will tell you how to create virtual host Apache on Ubuntu.

How to create Apache virtual host in Ubuntu?

Before knowing the process to create a virtual host Apache in Ubuntu, we want to tell you what it is and why a virtual host or virtual hosting.

What is a virtual host?

A virtual host or virtual hosting, in Spanish, is a computer infrastructure that allows a series of websites, platforms or applications to be stored on the same server. Here you can establish all the elements that you consider necessary, without having to divide yourself, in economic or space terms, since everything will be contained in a single server or virtual host. However, each site will have a different administration and form of control. Therefore, you will be able to store data, applications and services within the same place.

Steps to create Apache virtual host in Ubuntu

Now that you know what a virtual host, you will surely be interested in knowing how one is created. Therefore, below, we will tell you the steps to create virtual host Apache on Ubuntu.

Install Apache and other important dependencies

First of all, you must keep in mind that you must have installed in Ubuntu a sudo-enabled non-root useras well as the Apache application. You do this with the following instruction, basic for installing elements in Ubuntu:

sudo apt-get update
sudo apt-get install apache2

Afterwards, you can start creating the virtual hosting infrastructure.

Create the directory structure

The next step focuses on creating a directory that will store all the relevant data and information from the sites of the virtual hostwhich will be presented to users.

To create the directory, you must use the mkdir command under sudo, as follows:

sudo mkdir -p /var/www/namedeserver.com/publico_html
sudo mkdir -p /var/www/testdelserver.com/publico_html

Give permissions

Now that you have your directory established, you must give access permissions to users so that they can explore the directory with all the files found there. To do this, you must use the chown command under sudo in Ubuntu.

sudo chown -R $USER:$USER /var/www/servername.com/publico_html
sudo chown -R $USER:$USER /var/www/testdelserver.com/publico_html

The method of user will be parameterizable to any user who is using the virtual host. You have to make sure that the user can read all the data with the Ubuntu chmod method.

Create demo pages

After this, you will have to create a demo page, which will be able to establish how the content from the servers will be presented. To do this, you will only have to use the instructions for creating a page, such as:

nano /var/www/example.com/namedeserver.com/index.html

On the other hand, you must attach all the necessary elements under the html index, using the same markup language and any other tool that you think is important.

Create new files and activate them

Now, let’s create our first files in our host virtual. To do this, you can copy the code extract that we present below. In it, you will establish the adminthe name of the serverthe name of the alias, the path where the document will be found and the costum log.

ServerAdmin [email protected]
ServerName example.com
ServerAlias ​​www.servername.com
DocumentRoot /var/www/namedelserver.com/publico_html ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Afterwards, you will have to activate each of the files as follows:

sudo a2ensite servername.com.conf
sudo a2ensite test.com.conf

Once done, you will have to restart Apache for all changes to be established, with sudo systemctl restart apache2.

Finally, take a test of your virtual host!

Do you want to learn more?

Now that you know how to create virtual host Apache on Ubuntu, you are ready to create yours. Remember that you can always return to this article to complete each of the steps.

Now, if you would like to learn more fundamental concepts or tools for the programming path, we invite you to visit the program Full Stack Jr. Bootcamp Learn to Program from Scratch. If you want to change your life and enter this highly employable sector, ask for more information!

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *