Debian in VirtualBox for local web development
Have you ever wanted to develop your web application locally. Using VirtualBox you can develop with a near clone of your production environment. Giving you a personal sandbox where you can go crazy before you commit to your teams development server.
The first thing we need to do is install virtualbox. Go to the? virtualbox download page and get the software package that appropriate for your platform and run the installer once downloaded. Linux user should be able to install it using their distro's software management tool. The windows installer will walk you through a couple of steps. For the most part you can use the defaults. Though I always un-check add icon to desktop when I install software.
Go to Debian's network install iso page to download the stable iso file we will use to install from. Save the file someplace convenient where we can find it later. The Linux distro doesn't matter, if you can you should use the same as is on your production, staging and testing environments. The more things we keep the same across uses the fewer surprises there will be down the road.
Once we have VirtualBox installed and the Debian iso downloaded we are ready to install. Run VirtualBox and click on the blue starburst to create a new virtual machine. Name the virtual machine something short and easy, no crazy characters, something like local-dev. We can use this name later for the machine name, which will help us keep things straight. Now change the Operating System type to Linux and the version to Debian. Next you can set the memory to 128MB if you only installed the base system. You might need to set the memory to more depending on the amount of software you installed in the virtual machine. Next you should choose to create a new virtual hard drive. What was true with memory will be true here. You don't need a huge virtual hard drive size, 1.5GB should be enough for a simple install, but the more software you want the larger virtual hard drive you will want to create. I choose to create as small as possible size because I am only using it for web dev testing and it's not going to actually host any of the source files. Now the virtual machine setup is finished.
Before we install Debian we need to tell the virtual machine to boot from the iso we downloaded. Select your new virtual machine and click on the yellow settings button shaped like a gear. Here we have access to all the options for the virtual machine. We want to click on CD/DVD-ROM, and add a check next to Mount CD/DVD Drive. Then we want to put a dot next to ISO Image File. Now click on the yellow folder with the green up arrow to the right. This will take us to the virtual media manager. While on the CD/DVD Images tab click on the Add icon and navigate to where you saved the Debian iso file. Once it's added select it and click on the select button. Now click on OK to close the Settings dialog box.
With your new virtual machine selected click on the green start arrow. The virtual machine will now boot from the iso and being to the install process. It's best to follow the Debian install documentation to get the system installed and up and running. Once the OS is done installing run aptitude and install apache, php and other servers do your liking.
Configure apache, php, et al. in the? We want to make a point of configuring Apache to point to a specific directory, the one we will later mount our source code on.
Now that Debian is installed and our servers are configured we want to switch to host-only networking. You can use Bridge networking too, but I prefer host-only as it keeps a constant IP address for my virtual machine when I move my laptop from location to location. First you must halt the virtual machine before you can edit any of the settings. In the settings dialog choose the Network item and change the Attached to: option from NAT to Host-Only Adapter. The VirtualBox Host only Ethernet Adapter should be selected below it. I also take this time to un-check Mount CD/DVD Drive under the CD/DVD-ROM option. Select OK to close the Settings dialog. Now we are
Now we need to make it easy to access our local server by editing the host file. The host file lets us create alias names for servers. The Linux host file will be at /etc/hosts and the windows host file will be at %SystemRoot%\\system32\\drivers\\etc\\
Add this line:
192.168.56.107 ???????????? local-dev.example.com ? local-dev
Where the IP address is the one assigned to your dev server in VirtualBox and local-dev is the host name you want, and example.com is a domain name you want. Really you only need the host name.
You will also have to setup the same host file on the local-dev virtual machine.
Now we want to setup a samba share (or setup a Windows share) on our host machine that will share the directory our source code is stored in.
Once the share is ready we want to mount the share in our local-dev machine.
Now we have the local-dev maching mounting the source code from the host to the root directory where apache is serving. We can now go to http://local-dev in our web browser and we should see the files as they are served up by apache. Now we can edit our source locally and test the results immediately from the local apache install.