Testing a website in Safari with Mac OS X VirtualBox

Developing a website on a Linux operating system is pretty comfortable, but unfortunately are the most users of those websites using other operating systems with other web browsers. There is a nice solution for the Windows Internet Explorer or Edge browser, free Virtual Machines from IE8 to MS Edge. Unfortunately I have not found an easy way to setup a VirtualBox with Mac OS X to test a website in the Safari web browser. My colleague Jan Knipper pointed me to vagrant-box-osx, a Mac OS X Vagrant box for VirtualBox by Andrew Dryga.

Creating a Mac OS X Vagrant VirtualBox

I will just follow the README.md of vagrant-box-osx and assume that Vagrant and VirtualBox is installed.

vagrant init

Run the following command in your project directory.

vagrant init http://files.dryga.com/boxes/osx-sierra-0.3.1.box

The command should have created a Vagrantfile in your current directory. Please find the following part in your Vagrantfile.

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Don't boot with headless mode
  #   vb.gui = true
  #
  #   # Use VBoxManage to customize the VM. For example to change memory:
  #   vb.customize ["modifyvm", :id, "--memory", "1024"]
  # end
  #
  # View the documentation for the provider you're using for more
  # information on available options.

And uncomment a few lines to enable the graphical user interface so it looks as follows.

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Don't boot with headless mode
    vb.gui = true
  #
  #   # Use VBoxManage to customize the VM. For example to change memory:
  #   vb.customize ["modifyvm", :id, "--memory", "1024"]
  end
  #
  # View the documentation for the provider you're using for more
  # information on available options.

Or you can remove all comment and your Vagrantfile should look like this.

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "http://files.dryga.com/boxes/osx-sierra-0.3.1.box"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
  end
end

vagrant up

The following command will download the box and will start the Mac OS X machine.

vagrant up
Mac OS X Vagrant VirtualBox

Reach webserver of host machine

We can reach the webserver of the host machine with the IP 10.0.2.2 in the Safari web browser.

Next Previous