Then, the root directory of the virtual host has been successfully created, and this is also the time to set up Apache to begin the process of creating a new website. After completing this Apache configuration step, the entire website will be built inside / var / www / test_site.
The first step in setting up Apache is to make sure that Apache 'knows' that the virtual host is enabled. Specifically, in the configuration section of Ubuntu, go to the following paragraph in file / var / www / test_site:
Make sure this line of code is still active (does not start with # ). The sites-enabled command structure will be pointing to / etc / apache / sites-enabled . When searching in that directory, we will see that there is a 000-default file - which contains information about all the necessary directories for the virtual site to be created later. And to create a new virtual host, we need to create a new file inside the available directory, which is / etc / apache / sites-available / test_site . Specifically, the content of that file will look similar to the following:
ServerAdmin webmaster @ localhost
#We'd like to be able to access web site using www.test.domain.com or test.domain.com
ServerAlias www.test.domain.com
DocumentRoot / var / www / test_site
#log file for this server
CustomLog /var/log/apache2/www.test.domain.com-access.log combined
The above code is used in case of assuming that domain.com will be the domain used (replacing this value with the domain name you use). And besides, we need to do 2 more simple steps below before restarting Apache. The first is to initialize the connection path in / etc / apache / sites-enabled to the newly created file:
- Access the directory / etc / apache / sites-enabled with the cd command / etc / apache / sites-enabled
- Create connection path using sudo ln -s / etc / apache / sites-available test_site command
Besides, we can also create links automatically by using sudo a2ensite test_site , and then temporarily disable virtual site operation, remove the connection with the sudo a2dissite test_site command .
And the last step to make sure that the server 'knows' about the existence of virtual site is not over the Internet. Specifically, we need to do the following:
- Open the / etc / hosts file with any text editor with Administrator rights
- Add the line of code 127.0.0.1 localhost.localdomain localhost test.domain.com www.test.domain.com
- Save and close the file.
Restart Apache with the sudo /etc/init.d/apache2 command and restart the virtual host by typing the address into the browser.
If the server system hosting virtual site is not a Debian-based distributor, some setup steps will be slightly different. As follows:
- Create a directory containing virtual site in the file /etc/httpd/conf/httpd.conf - similar to the Debian system.
-Make sure that the Apache configuration file is 'aware' of the virtual host's existence by maintaining the functionality of the Include conf.d / *. Conf code .
- Create a new virtual host file (often called vhosts.conf ) in the /etc/httpd/conf.d/ directory
- Add virtual site to the / etc / hosts file
- Restart Apache with the command /etc/rc.d/init.d/httpd restart
Our storage directory (for non-Debian systems) will look similar to the following:
ServerName test.domain.com
DocumentRoot / var / www / html / test_site
The virtual host file mentioned above will look like this:
DocumentRoot / var / http / www / test_site
ServerName www.test.domain.com
DocumentRoot / var / http / www / test_site
ServerName test.domain.com
This is also the time when the virtual host has been set up and working properly, and the next is to build the website within the directory / var / www / test_site . We can do this with multiple virtual host systems at will, or with tools like Drupal, Xoops or Joomla. Good luck!