2

How to access from the host the Apache virtual domain created on virtual machine.

Settings of the VM on VirtualBox:

  • VM ubuntu/precise32 on VirtualBox created with vagrantfile from How to setup a LAMP development environment in Vagrant by Sanchit Jain Rasiya
  • installed Apache/2.2.22
  • installed Lynx browser
  • Virtual Host /etc/apache2/sites-available/example.com

    ServerAdmin webmaster@example.com ServerName example.com DocumentRoot /home/vagrant/www/example.com AllowOverride All Order allow,deny Allow from all ErrorLog "/home/vagrant/www/example.com/logs/example.com-error.log" CustomLog "/home/vagrant/www/example.com/logs/example.com-access.log" combined

From the browser on the host machine I can access VM's localhost as http://192.168.205.10/index.html How can I access VM's example.com?

On the host's /etc/hosts I have added line for example.com

127.0.0.1   localhost
127.0.0.2   tmp.loc
127.0.0.3   temp.loc
192.168.205.10  example.com

When I try http://example.com/mj.html I get the 404 Not Found page from Apache/2.2.22 (Ubuntu) Server at example.com Port 80

On the virtual machine I can access page with the Lynx

lynx http://example.com/mj.html

This is noted in the /home/vagrant/www/example.com/logs/example.com-access.log file as

127.0.0.1 - - [03/Apr/2016:15:53:49 +0000] "GET /mj.html HTTP/1.0" 200 344 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.14"

But when I try to access example.com from the host there are no logs neither in access.log nor /home/vagrant/www/example.com/logs/example.com-error.log

There are no logs in the host's Server files /opt/lampp/logs/access_log and /opt/lampp/logs/error_log

jaquar c
  • 31
  • 1
  • 4

2 Answers2

1

On Ubuntu /etc/hosts:

127.0.0.1       localhost
127.0.2.2       example.com

On Windows (VBox) C:\Windows\System32\drivers\etc\hosts:

10.0.2.2 localhost
10.0.2.2 example.com

Then just reboot your VBox Windows and type in browser (on Windows): http://example.com/

mathematicalman
  • 306
  • 1
  • 7
0

I have the same issue, I've been trying to access my drupal project from my virtualbox vm but it is not working. One of the solutions I found on the Internet is using the outer keyword in your hosts file in the VM.

The following works fine for me:

  1. In your host machine (let's say a ubuntu) type: ifconfig, and get the inet address of wlan0 (example: 192.168.1.15)
  2. Add this address to the host file in your virtualobox machine and use the outer keyword

    [192.168.1.15 outer]
    

Now you can access your localhost from your virtualbox browser by typing the address of your wlan0 (ex: 192.168.1.15).

  • If you need to access a specific port on your host add the port number to the address example 192.168.1.15:8001
Antwane
  • 20,760
  • 7
  • 51
  • 84
soukaina
  • 49
  • 7