[Drupal] How can we test a Drupal local site in multiple machines by creating virtual host

| | 2 min read

When your trying to implement a new feature(say a module or theme) in your local machine for a website, first thing you have to test is the compatability in all browsers. If you want to test your feature in multiple machines, its not always easy to download and setup on each machine. In my case, I am using Ubuntu and I have to always test compatability of a site in IE browsers which cannot be installed in ubuntu. So what I did here is created a virtual host for my site in my local machine and using my ip address I created a virtual host in other machines so that I could easily access all my sites in my local machine from diffrent machines.

Following steps have to be followed test a Drupal local site in multiple machines by creating virtual host.

First download and set up a drupal site in your machine. Once its done create a virtual host for your site in local machine.

Step 1: Take terminal and goto etc folder

cd /etc

Step 2: There is a host file in etc folder edit this using following command

sudo gedit hosts

Step 3: Now add the following lines

127.0.0.1	hostname

Example :

127.0.0.1	servertest

Step 4: Goto apache2->sites-available folder

goto cd apache2/sites-available/

Step 5: Create a file of hostname. Using following command

sudo gedit hostname

Example

sudo gedit servertest

Step 6: Add following lines to the file created


<VirtualHost *:80>
ServerName hostname
DocumentRoot full_path_of_folder
<Directory full_path_of_folder>
AllowOverride All
</Directory>
</VirtualHost>

Example


<VirtualHost *:80>
ServerName servertest
DocumentRoot /var/www/servertest
<Directory /var/www/servertest>
AllowOverride All
</Directory>
</VirtualHost>

Step 7: Type following command to enable host name

 sudo a2ensite "hostname"

Example:

sudo a2ensite servertest

Step 8: Restart Apache

sudo /etc/init.d/apache2 restart

Now your virtual host is ready. Type "servertest/" in your browser and if your site is ready, you can see your site.

Now if you want to test your site in other machines say for windows or in Ubuntu. Do the following steps

For windows

Step 1: Goto following location "C:Windows/system32/drivers/etc"

Step 2: You can find "hosts" file here. To get your IP goto google and type my. Now edit hosts files as follows

my ip hostname

Example

ip_address servertest

Step 3: Type "servertest/" in the browser and you can see your local site here.

For Ubuntu

Step 1: Goto following location "/etc"

cd /etc

Step 2: There is a host file in etc folder edit this using following command

sudo gedit hosts

Step 3: To get your IP goto google and type my and add following line

my ip hostname

Example

ip_address servertest

Step 3: Type "servertest/" in the browser and you can see your local site here.

Here only advantage is that you can test a local site in different sytems without setting them on each machine.