04-07-2017, 08:14 AM
What is Apache Virtual Hosts?
Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers). This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.
You will also need to have Apache installed in order to work through these steps. If you haven't already done so, you can get Apache installed on your server through
After these Steps we have successfully Installed Apache in our Vps So now we get start for example we will create two virtual hosts 1 kabir.com and another vps13.com this is just for example you can change these name to yours
so now first of all we will create directories and then we will setup the configuration file
for creating directories type the following commands
after creating directories now we will grant permissions to them by typing the following commands
now we should modify our permission in order to amke it readable you can do it by typing the following command
Now we setted up the permissions
Now we will create a Example file in our folders in order to check it its working or not
So for create files in folders you will need nano if you dont have you can install it by typing the following command
So we will create file with the following command
In this Create a simple html document mine file looks like /
now save it and close it its done now we will create a file for vps13.com also
so we will create file for vps13.com with the following command
In this we will create a simple html document mine file looks like this
So Now Close it it and save it now will create virtual hosts files
So we will start it by copying first domain file we can do it by the following command
Code:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/kabir.com.conf
now open your with editor ffor modifying you do it with the following command
the file will looks like this but from this file i have removed useless comments
As you can see there are not much we will customize it and will add some more things
First of all you need to change the Serveradmin Email change it to your email from which you able to recive emails
Code:
serveradmin [email protected]
After this we need to add two more things no 1 is servername and second is serveralias so you add them like that
the last thing we have to change is location change its location to your site directory like here we did
in total our virtual file should looks like this
First Domain virtual host has been done we will start for second domain vps13.com
So now we will again copy that file for our second domain file with the following command
now you have to open it with nano editor in order to customizze it you do it with the following command
our virtualhost file will looks like this from this i have removed useless things
as you you can see this is not complete so we have to customize it for our second domain file
First of all you need to change the Serveradmin Email change it to your email from which you able to recive emails
After this we need to add two more important things which is servername and serveralias you can add them like
the last thing we have to change is location change its location to your site directory like here we did in our first domain but i will repeat it again
in total our virtual file should looks like this
now we have done it for our both domains so now save the file and close it
So now we have created cirtualhost ffiles but now we have to enable them for that apache allow us to do it with a command you can do with the following command
After this we have to restart apache we can do it with the following command
Code:
now we are done you are ready to visit your site
Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers). This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.
You will also need to have Apache installed in order to work through these steps. If you haven't already done so, you can get Apache installed on your server through
Code: (Select All)
sudo apt-get update
sudo apt-get install apache2
After these Steps we have successfully Installed Apache in our Vps So now we get start for example we will create two virtual hosts 1 kabir.com and another vps13.com this is just for example you can change these name to yours
so now first of all we will create directories and then we will setup the configuration file
for creating directories type the following commands
Code: (Select All)
sudo mkdir -p /var/www/html/kabir.com/
sudo mkdir -p /var/www/html/vps13.com/
Code: (Select All)
sudo chown -R $USER:$USER /var/www/html/vps13.com/
sudo chown -R $USER:$USER /var/www/html/kabir.com/
Code: (Select All)
sudo chmod -R 755 /var/www
Now we will create a Example file in our folders in order to check it its working or not
So for create files in folders you will need nano if you dont have you can install it by typing the following command
Code: (Select All)
sudo apt-get install nano
Code: (Select All)
nano /var/www/html/kabir.com/index.html
Code: (Select All)
<html>
<head>
<title>oye hoe its working</title>
</head>
<body>
<h1>kabir is working perfect!</h1>
</body>
</html>
so we will create file for vps13.com with the following command
Code: (Select All)
nano /var/www/html/vps13.com/index.html
Code: (Select All)
<html>
<head>
<title>oye hoe its working</title>
</head>
<body>
<h1>vps13 is working perfect!</h1>
</body>
</html>
So we will start it by copying first domain file we can do it by the following command
Code:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/kabir.com.conf
now open your with editor ffor modifying you do it with the following command
Code: (Select All)
sudo nano /etc/apache2/sites-available/kabir.com.conf
the file will looks like this but from this file i have removed useless comments
Code: (Select All)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
As you can see there are not much we will customize it and will add some more things
First of all you need to change the Serveradmin Email change it to your email from which you able to recive emails
Code:
serveradmin [email protected]
After this we need to add two more things no 1 is servername and second is serveralias so you add them like that
Code: (Select All)
servername kabir.com
serveralias http://www.kabir.com
the last thing we have to change is location change its location to your site directory like here we did
Code: (Select All)
DocumentRoot /var/www/html/kabir.com
in total our virtual file should looks like this
Code: (Select All)
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName kabir.com
ServerAlias www.kabir.com
DocumentRoot /var/www/html/kabir.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So now we will again copy that file for our second domain file with the following command
Code: (Select All)
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/vps13.com.conf
now you have to open it with nano editor in order to customizze it you do it with the following command
Code: (Select All)
sudo nano /etc/apache2/sites-available/vps13.com.conf
our virtualhost file will looks like this from this i have removed useless things
Code: (Select All)
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
as you you can see this is not complete so we have to customize it for our second domain file
First of all you need to change the Serveradmin Email change it to your email from which you able to recive emails
Code: (Select All)
serveradmin [email protected]
After this we need to add two more important things which is servername and serveralias you can add them like
Code: (Select All)
servername vps13.com
serveralias http://www.vps13.com
the last thing we have to change is location change its location to your site directory like here we did in our first domain but i will repeat it again
Code: (Select All)
DocumentRoot /var/www/html/vps13.com
in total our virtual file should looks like this
Code: (Select All)
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName vps13.com
ServerAlias www.vps13.com
DocumentRoot /var/www/html/vps13.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So now we have created cirtualhost ffiles but now we have to enable them for that apache allow us to do it with a command you can do with the following command
Code: (Select All)
sudo a2ensite kabir.com.conf
sudo a2ensite vps13.com.conf
After this we have to restart apache we can do it with the following command
Code:
Code: (Select All)
sudo service apache2 restart