Taking PHP development seriously, it is not very uncommon practice to do cross-platform tests of own code. With virtual machines it is dead easy to test your PHP code on three popular systems (Mac OS X, Linux and Windows) using only one physical machine. To make it even more pleasant all systems can share PHP code from one location hence there is no need to copy every time you want to test. And here comes the cream: you can get fully-blown eye-candy virtualizer for free.
VirtualBox is good and is free!Yes, that is correct. VirtualBox is free and made by SUN. It is good piece of software, very reliable and easy to use. You can get VirtualBox for Windows, Mac or Linux.
VirtualBox performance on Mac Mini
Running both virtual boxes with AMPs on them along with MAMP on the hosting Mac did not visibly affect overall host system responsiveness. I could have Chrome, Firefox, Aptana, Preview, iTunes, Skype and Activity Monitor running concurrently and smoothly. Only Spaces (9 desktops) were a bit more choppy than usual. Each of the virtual boxes was also responsive.
Both guest systems were visible and accessible over the local network. They could easily obtain IP addresses from DHCP server existing within the network. All the network communication was also reliable except for situations when one of the boxes (either real or virtual one) generated heavy traffic on the network interface. Downloading 100MB from Internet at 200kB/s was enough to cause connection disruption.
Set up Mac OS X host systemIf you are PHP developer working on Mac, probably you already have half of the work done. Nevertheless assuming you are starting from scratch the following steps need to be accomplished:
Create WAMP virtual machine on your Mac
Create new virtual machine for Windows.Simply go to Machine -> New. Then just follow the guide, it takes about 2 minutes. There are no difficult questions and if you want to know more - the help is really good. I have created Virtual Machine called "virtual-winxp" with 256MB of RAM and 2GB of new virtual hard drive being dynamically expanding storage. The network adapter I have chosen was bridged adapter. The latter is important if you want to have access to LAN and Internet from your the guest OS and be able to access the guest OS from your Mac.
Install your preferred version of Windows.My Win XP installation process was real time. When installer announced 30 minutes left - it was 30 indeed minutes. Network name of my Win XP was again "virtual-winxp".
Download WAMP and install itNothing I could think of to add here.
Install VirtualBox Guest AdditionsGo to Devices -> CD/DVD Devices and choose VBoxGuestAdditions.iso. You can do so even when the guest OS is running. Virtual CD will appear in your drive and you will know what to do. VirtualBox Guest Additions are essential if you want to share your PHP code with the host OS.
Configure shared folder/Applications/MAMP/htdocs/projects and name it, say "projects". Now that folder will be accessible from Windows as pseudo network drive \\vboxsrv\projects. It is probably a good idea to make it permanent if you don't want to repeat this step every time you start your guest OS.
Configure your WAMP to use projects folderhttp://virtual-winxp/projects. Go to your Windows, click on the WAMP icon in system tray, choose Apache -> Alias directories -> Add an alias. When the command window appears, type in the alias name "projects".
On the second screen enter the real directory name being "//vboxsrv/projects". Forward slashes are not a mistake, Apache for Windows likes it like that. Your WAMP should restart and when you go to http://localhost/projects you should see your Mac projects directory.
Make your WAMP visible for your MacIf you prefer to test results of your PHP on your Mac (who wouldn't) rather than on the guest OS, it might be a good idea, to make your WAMP visible in the local network. All you need to do is click on your WAMP icon in system tray, choose "Put Online" and wait till the Apache restarts.
Create LAMP virtual machine on your Mac
Create new virtual machine for your LinuxSimilar procedure as for virtual machine for Windows, only different name ("virtual-debian" in my case). Settings exactly the same: 256MB RAM, 2GB virtual HDD expanding storage and bridged network adapter. Please remember, that the bridged network adapter is important if you want to access LAN and Internet from your guest OS and also access the guest OS from your Mac.
Install your preferred distribution of LinuxI have chosen Debian because it has very good package management and I like it. The hostname I set for it was again "virtual-debian".
Install nanoAs mentioned before, you might need to change a few config files. If you are not familiar with vim it is probably a good idea to install more friendly console editor. When logged in as root run:
#aptitude install nano
Prepare for installing VirtualBox Guest Additions
I got result like this:
Once you know the version it's time to install headers. Simply repeat the version at the end of linux-headers package:
#aptitude install linux-headers-2.6.26-2-amd64
The installer might ask you a few questions, for example about installing additional packages. It's safe to answer "yes" to all of them.
Install VirtualBox Guest AdditionsAgain, go to Devices -> CD/DVD Devices and choose VBoxGuestAdditions.iso. You can do so even when the guest OS is running. Virtual CD will become ready for you to mount and access it:
Then you need to copy installer to your hard drive:
#cp VBoxLinuxAdditions-amd64.run /~
and run it:
Configure shared folderSame as with Windows virtual box. That would allow you to share your PHP code with the host OS. Go to Devices -> Shared Folders... and click "Add shared folder" icon - the one with "+" sign. Then choose your projects folder from Mac, say /Applications/MAMP/htdocs/projects and name it, say "projects". Now that folder will be available to mount from your Linux (Debian) as... projects (read next point for explanation). It is probably a good idea to make it permanent if you don't want to repeat this step every time you start your guest OS.
Configure your Debian to mount shared folder on startuphttp://virtual-debian/projects and you don't want to mess around with Apache config too much (at least at this point) simple create the mount point and mount:
#mount -t vboxsf projects projects
Now inside projects directory you should see contents of your Mac projects directory. To make this mount occur every time you start your Linux, you need to add a line to /etc/fstab config file. Open the file:
and add the following line:
projects /var/www/projects vboxsf ro 0 0
Save the file and you are sorted. From now on, whenever you boot Linux the folder will be mounted for you and ready to use. And don't worry about the mount error - it's because default Linux mount happens before the vboxadd service is loaded.
Setup Fixed IP Addresses for your Virtual Farm
Access your virtual boxes by names
here you enter your password, and then edit the /etc/hosts file:
Here you need to add one line for each virtual box. First IP then the name you like, for example:
Save it and job done.
Thanks for reading. I hope you found this guide useful, it worked for you and made you a bit happier. Please don't think twice before you leave your comment.