Access Apache on VirtualBox OS from Host OS

Access Apache on VirtualBox OS from Host OS

Problem

You have a RHEL or CentOS 6 VirtualBox Virtual Machine and a Windows or other host and would like to access a web server on the VM from the Host OS.

Solution

Assure that the Apache Web Server is available and started on the guest OS:

`sudo httpd start`

Assure that firewall allows the guest OS to handle web requests.

Type ` sudo system-config-firewall` and enable the WWW service.

Configure port forwarding for the VM. Go to the VM settings in the Oracle VM VirtualBox Manager / Page 'Network'.

Click on the button [Port Forwarding] and add an entry such as the following:

Now, on your host OS, you should be able to see the Apache Server test page when opening `http://localhost:8080\` in a browser.

Troubleshooting

Since every system is configured differently there might be some problems you encounter. If you don't see the test page, you could try the following:

  • Disable SELinux by opening the file ` /etc/selinux/config` and setting the configuration to ` SELINUX=disabled` (see a more detailed guide here)
  • This tutorial assumes that you use the default NAT network adapter for you VM. If you use a 'host-only' or 'bridged' connection, the process will be a bit different.

References

Stackoverflow - How to SSH to a VirtualBox guest externally through a host? Very helpful, also read the comments

Stackoverflow - Apache restart causes DocumentRoot must be a directory, even though it is a directory and there seem to be no privilege issues

CentOS Board - Basic firewall config (just port 80 and ssh 22)