Instructions for creating virtual hosts with Apache in Ubuntu
TipsMake.com - For system administrators, Apache is indeed one of the most effective support tools today, with flexibility and high stability, easy to set up, configure, support. managing multiple domains even if the web server system has only one IP address. Besides, we can also use it to host many different sites, or simply set up a sandbox system for application development. In the following article, we will cover some basic operations to create virtual host - virtual host using Apache.
In essence, the process of setting up a host is a 'challenge', but it is not so simple. Users can completely set up a virtual host system with just a few simple steps such as custom changes in Apache. Specifically in this test, we use the Ubuntu server operating system and the corresponding Apache version.
Create directory structure:
Before embarking on the configuration process, you must complete the directory structure step for virtual sites. Here we will work with Apache installed on the Ubuntu server system, so the root document section of Apache will appear at / var / www. In essence, the directory structure for the new website can be created anywhere, possibly in the directory (~ /) , or / usr / local / apache . To simplify the maximum of this test, We will set up virtual host in the Apache root document section (in Ubuntu will be the directory / var / www ), with this step we will not need to change the ownership level of the directories created later. This or the root directory contains the virtual host.
Specifically, in this test we will set up virtual host test_site, and type the following command to create the directory containing virtual host:
sudo mkdir / var / www / test_site
sudo chmod -R 755 / var / www / test_site
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.
Configure Apache:
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:
Include sites-enabled /
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.
For non-debian server systems:
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!
You should read it
- Install and configure Apache in Ubuntu
- Deploy KMS activation on Windows Server 2008
- How to Install Ubuntu Server
- Installing Ubuntu in VirtualBox does not need DVD or USB
- Basic steps to set up virtual system with VirtualBox on PC
- Set up WebDAV with Apache2 on Mandriva 2010.1 Spring
- Use Quick Migration to move virtual machines between Hyper-V hosts
- What is a computer host file and how to edit a host file?
May be interested
- Install Cherokee with PHP5 and MySQL supported in Fedora 14currently, cherokee is one of the lightest web server, high flexibility and easy to configure and set up. in addition, it also supports many advanced technology platforms such as fastcgi, scgi, php, cgi, encryption connecting tls and ssl protocols, virtual hosts, encryption mechanisms, load balancing of resources, data data of the system, apache log file ...
- Instructions for installing Ubuntu Maverick in Mac Virtualboxin the following article, tipsmake.com will show you how to install and use ubuntu inside mac os x through virtualbox ...
- Instructions for installing LAMP on Ubuntu for beginnersin this article, we will show you how to install a lamp system. lamp includes linux, apache, mysql, php. this tutorial is primarily for people who have only a little knowledge of linux use.
- Install Ubuntu in Windows using the Wubi Installeryou want to find a solution to try ubuntu but don't like the idea of creating a partition, using the cd drive directly, or not having enough resources to run a virtual machine. try using the wubi installer program to run to ubuntu.
- How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04ispconfig is an open source control panel that allows users to manage multiple servers from a single interface.
- Instructions for installing Ubuntu on VMware Workstation - Part 2in the previous section of the article, we jointly established vmware and ubuntu desktop. and the next section below, please continue with the steps to install ubuntu desktop on vmware workstation.
- How to modify and manage Hosts files on Linuxif you need to block web pages or create personalized web shortcuts on linux, solve these tasks by adding or adjusting a few lines in the hosts file.
- Instructions to restore the hosts file on Windows to defaultdetailed instructions on how to restore the hosts file on windows to default, like when windows was installed. how to reset the hosts file on windows is the fastest and easiest way
- Instructions for installing Ubuntu on VMware Workstation - Part 1for some reason, can't you continue to use windows (royalties)? you want to discover a certain operating system that is enough to replace the already familiar windows? you just need 1 software, some operating system to meet the needs of working very simple? check out the free and completely open source ubuntu operating system.
- Instructions for installing Ubuntu Web Server on remote hostin the following article, we will show you how to install and configure ubuntu web server system on remote host. to do this, you need to prepare several factors as follows ...