Image sourced from JesseForrest.name
Throughout my web development experiences, I have worked with numerous environments – both virtual/cloud-based, and locally on physical machines. While developing web applications on my physical machine, I like to keep the development environment separate from the rest of my machine – which is why I prefer to develop in a virtual environment. Numerous software packages, such as VirtualBox and VMWare, enable you to set up an environment on your machine relatively easily – which is where this post comes in.
This six part guide aims to show how I set up my virtual development environment on my machine – including the program for setting the environment up, the environment’s operating system, and extra features within this environment. You don’t have to use exactly every tool/implementation in this post – it is merely a guide for you to work with, as well as a refresher exercise for myself.
For this particular guide, you will need the following to work yourself through it:
- VirtualBox (already installed)
- Debian Operating System ISO file
- An F.T.P client (I will be using FileZilla for this guide) (already installed)
- Git Bash Shell (already installed)
- Working internet connection (preferably broadband)
We will also be installing the following components on our web development server:
- The L.A.M.P stack (Apache version 2.2.22, PHP version 126.96.36.199, and MySQL version 5.6.21)
- Git (usually installed by default)
- Varnish Caching
I am also using VirtualBox on my Windows 8.1 O.S, so instructions might need to be adjusted slightly for other types of operating systems.
Without further ado, I’ll begin the guide…
Open the VirtualBox program. You should be presented with a similar view as in the screenshot below:
You may notice that there is already a virtual environment installed. This is the one where I currently do my local development. This was created via the use of Vagrant – a tool which makes it easier and faster to deploy development environments. I will not be using Vagrant in this particular guide, but I may consider writing a similar guide for it at a later point. For those who are interested, I used the following Vagrant box to create my environment (with my own extra bits): https://vagrantcloud.com/chef/boxes/debian-7.6.
We are now going to create a new virtual development machine.
To begin, click on the bluish pointed star ‘New’.
Then fill out the following information for the three fields:
- Name: Debian Dev Machine
- Type: Linux
- Version: Debian (64 bit) (or 32 bit, depending on the ISO you have)
You should now have something like the screenshot below:
Once you have entered the information, click on the ‘Next’ button
You will now be guided through the installation process – setting resource limits and so forth for the machine.
For ‘Memory Size’, you can leave the default value (512 MB). If you have enough memory resources on your physical machine, you can choose a higher value. For this guide, I am using 2048 MB. Click Next when you have entered your desired value.
For ‘Hard Drive’, select the ‘Create a virtual hard drive now’ option. Then click ‘Create’.
For ‘Hard drive file type’, select ‘VMDK (Virtual Machine Disk)’. Then click Next.
For ‘Storage on physical hard drive’, Select ‘Dynamically allocated’. You can leave the ‘Split into files of less than 2GB’ option unchecked if you wish. Then click Next.
For ‘File location and size’, leave the default value in the input field. For the virtual hard drive’s size, 10GB should be sufficient. Now click on the Create button. When you click the button, your virtual image files should be saved in a location like ‘C:UsersyouVirtualBox VMsDebian Dev Machine’ (if you left the default input field value).
After clicking the Create button in Step Three, you should be presented a view like in the following image:
Our new machine is highlighted above with a blue-like colour. This completes the initial setup of our VirtualBox machine.
Now we are going to configure some extra settings – including adding our Debian ISO image, and forward a couple of ports (80 and 22). To do this, right click on the blue highlighted image and select ‘Settings’. You should be shown something like the following image:
To add our Debian ISO image to our virtual machine, click on the ‘Storage’ option on the left-hand side.
Once you have done this, click on ‘Empty’ under ‘Controller: IDE’ in the ‘Storage Tree’ section.
Then in the ‘Attributes’ section, click on the little CD icon – placed on the right-hand side of the ‘IDE Secondary Master’ dropdown dialog. You should see something like the image below:
When you have clicked on the CD icon, select the first option displayed to you – this should be called “Choose a virtual CD/DVD disk file”, as in the image above.
After clicking on this option, browse to the location where you downloaded your Debian ISO file. For me, the ISO file I will be using is ‘debian-7.7.0-amd64-DVD-1.iso’. When you have selected your ISO file, click on ‘Open’, then also the ‘OK’ button.
You have now loaded the ISO image to your Virtual Machine.
Here we will be forwarding ports 80 (the standard web port) and 22 (the standard SSH port). We are forwarding ports for our machine in case you have multiple machines running, and the standard ports are already being used. This is so any conflicts around port usage will be taken away.
To do this, right click your new Debian machine and select the Settings option. Then on the left-hand side, select the Network option. Once you have done that, click on ‘Advanced’ – this will show some extra options, as in the following image:
Once you have clicked on the Advanced option, click on the ‘Port Forwarding’ button. Upon doing so, we will be shown something like the image below:
This is where we will be adding the port forwarding rules.
For the first rule, use the following information:
- Name: http
- Protocol: TCP
- Host IP: 8888
- Guest IP: leave blank
- Guest Port: 80
For the second rule, use the following rules:
- Name: ssh
- Protocol: TCP
- Host IP: 2222
- Guest IP: leave blank
- Guest Port: 22
After you have entered the information, the port forwarding rules should look like the image below:
Once you have confirmed the two rules, click the OK button for the Port Forwarding Rules, then OK again for the Network settings.
This concludes our initial virtual machine set-up.
Part 1 Conclusion
For Part 1, we have managed to create a Virtual Machine with VirtualBox, attached our virtual machine’s OS ISO image, and configured some port forwarding rules to mitigate port-related conflicts. In Part 2, we will be installing the Debian operating system on our virtual machine, with some custom settings.
Part 1 Resources
- Oracle VM VirtualBox Manual
- How to Install Oracle VM VirtualBox and Create a Virtual Machine (on a Linux O.S)
- Debian — Getting Debian ISO Files
Feel free to comment below if you have any questions or are stuck with something :).