On my Ubuntu I run Apache vhost for each of my projects.
Now, wouldn’t it be cool if you could access your Apache vhost from IE running in VirtualBox!?
I managed to solve this problem by editing a Vbox instance settings:
Settings: Network: Adapter 1: Attached to: Bridged Adapter
Start a VirtualBox instance and type http://localhost in IE and you’ll see a localhost running on Ubuntu.
Now, associate IP address to a host name in Windows (192.168.1.38 is my Ubuntu IP address)
# c:/Windows/System32/drivers/etc/hosts
192.168.1.38 projectx.local
and Ubuntu
# /etc/hosts
192.168.1.38 projectx.local
Then create a new Apache config file
#/etc/apache2/sites-available/vbox-projectx
<VirtualHost projectx.local>
DocumentRoot /var/www/projectx
</VirtualHost>
Enable the config
$ sudo a2ensite vbox-projectx
$ sudo /etc/init.d/apache2 restart
Now, in IE (running in VirtualBox) type http://projectx.local and… that’s it
As a developer you most likely run dozens of projects in your webroot directory.
Setting up a new apache host and meddling through the apache conf files for every single project is just a waste of time. Not mentioning that conf file(s) can go huge over time. So, for the past six months or so I’ve been using a dynamic vhost configuration.
The concept is very simple. Let’s assume that you want to access each project via some dynamic domain like “$project.local”. “$project” would be a dynamic project name, and “.local” would actually be a localhost server.
First thing first, make sure that vhost module is enabled:
$ sudo cp /etc/apache2/mods-available/mod_vhost_alias.load /etc/apache2/mods-enabled/mod_vhost_alias.load
Now edit the default apache conf file:
$ sudo nano /etc/apache2/sites-enabled/000-default
Add following configuration to it:
<VirtualHost *:80>
ServerName local
ServerAlias *.local
VirtualDocumentRoot /var/www/%1/public_html
UseCanonicalName Off
</VirtualHost>
Retart the apache service
$ sudo service apache2 restart
Now the only “hard” part about this dynamic apache vhost configuration is that you have to set a new line ih hosts file for each project, which will point to local ip address. I’ve heard that this can also be dynamically ser over the bind DNS server, but I’ll explore that some other time
$ sudo nano /etc/hosts
127.0.0.1 local
127.0.0.1 foo.local