arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Apache Virtual host
#1
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 
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
sudo mkdir -p /var/www/html/kabir.com/
sudo mkdir -p /var/www/html/vps13.com/
after creating directories now we will grant permissions to them by typing the following commands
sudo chown -R $USER:$USER /var/www/html/vps13.com/
sudo chown -R $USER:$USER /var/www/html/kabir.com/
now we should modify our permission in order to amke it readable you can do it by typing the following command

sudo chmod -R 755 /var/www
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
sudo apt-get install nano
So we will create file with the following command 
nano /var/www/html/kabir.com/index.html
In this Create a simple html document mine file looks like /
<html>
  <head>
    <title>oye hoe its working</title>
  </head>
  <body>
    <h1>kabir is working perfect!</h1>
  </body>
</html>
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
nano /var/www/html/vps13.com/index.html
In this we will create a simple html document mine file looks like this
<html>
  <head>
    <title>oye hoe its working</title>
  </head>
  <body>
    <h1>vps13 is working perfect!</h1>
  </body>
</html>
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


sudo nano /etc/apache2/sites-available/kabir.com.conf


the file will looks like this but from this file i have removed useless comments
<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
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
DocumentRoot /var/www/html/kabir.com

in total our virtual file should looks like this

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

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


sudo nano /etc/apache2/sites-available/vps13.com.conf


our virtualhost file will looks like this from this i have removed useless things
<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

serveradmin  [email protected]

After this we need to add two more important things which is servername and serveralias you can add them like
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 

DocumentRoot /var/www/html/vps13.com

in total our virtual file should looks like this
<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>
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

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:
sudo service apache2 restart
now we are done you are ready to visit your site
#2
is virtualhost something like name of domain ? it can be publish ? sorry, but i never done virtualhost to publish it.....



person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting