Setting Up A Testing Environment For PHP Using VirtualBox - Part 1 Installing VirtualBox
In this tutorial I will show you how to download and install VirtualBox for your development environment. This is a software virtualisation package which we install on our computer, and through VirtualBox we can then install other operating systems and run them ‘natively’. So we can run a Linux server on a Windows machine. We do this for a few reasons:
- Every computer is different with regard to software, hardware and operating systems.
- Differences with your computer and the target server can be reduced by mimicking the server and running our test code on our test server.
- Cuts down the cost of not having to hire webspace or rent a cloud server.
- Allows us to have the exact same server configuration as our as the target server.
Installing the Required Software
To get our environment up and running we will need to first download the software from virtualbox.org, you should choose the binary that corresponds to your operating system. If you are running a Windows OS then click the Windows hosts link and if you are running OS X then click the OS X link, as I am using OS X then that’s the one I will download the download a copy of Ubuntu Server from https://www.ubuntu.com/download/server
Creating your virtual machine
First install VirtualBox the usual way you instal programs on your computer, once installed start the program and you should see a window like
To make your new virtual machine click 'New' and you will be presented with a new box entitled 'Name and operating system', fill the name out to 'Ubuntu Server' and 'Type and 'Version' should be automatically selected like below, we want the 'Type' to be 'Linux' and the 'Version' to be 'Ubuntu (64-bit)' if they are not selected then go ahead an manually select them
Next click 'Continue' and the next window entitled 'Memory size'. This option is how much RAM we are to allocate to our Ubuntu Server the default is 1024MB so if you have quite a bit of RAM then you can add more but don't go into the red area on the slider like below
Click 'Continue' and the next option is the 'Hard disk' make sure you have the 'Create a virtual hard disk now' and click 'Create'
The next window is 'Hard disk file type' just keep the default option of 'VDI (VirtualBox Disk Image)' and click 'Continue'
The next option is '' this option is how much space the virtual hard drive will take up on your physical hard drive, I would leave it on the 'Dynamically allocated' option as this will grow the dark drive to it's maximum limit you set, so if at the end of install the space taken by the files on the server is 3 GB then that's the physical size the image on your hard drive will be and will grow up to the maximum.
Click 'Continue' and and the next window is 'File location and size' here we define which folder to put our image the default is the name of our server which is fine and select how much space the hard drive will grow to the minimum is 8 GB but you can give to more if you wish.
Click 'Create' and it will create the virtual machine. When done you should have something similar to the picture below
Just a few more settings to adjust and then it's done, so with your Ubuntu Server selected click settings and in the new window entitled 'Ubuntu Server - General' click the 'System' icon and then the 'Processor' option if you have a quad core or more computer you can add more cpu resources to your virtual machine here as I have eight cpus I will increase this value to 4, but don't increase passed the red area as this will just slow things down.
Next click 'Display' icon and this option you can increase the video memory but as we are not using a desktop we can keep this low to say 12 MB
Next we have to add your Ubuntu live disk so we can install the system so click 'Storage' and select the 'Empty' disk icon under 'Controller.IDE' in the 'Storage Tree' panel then on the right under 'Attributes select the disk icon and add the iso you downloaded from Ubuntu by selecting the 'Choose Optical Disk File' option.
Just one more option to adjust so select the 'Network' icon and here we configure the network adapter the default is 'NAT' which means it will be allocated an IP on a new subnet of your network like '10.0.0.1' but we want it on the same subnet as our host computer so change the 'Attached To' option to 'Bridged Network' and choose the name of your hosts network adapter, if you are using WiFI to connect to the router choose that or the Ethernet option
And that's it, click 'OK' and we are ready to power our virtual machine up.
Installing the Ubuntu Server will be in part 2 of this series. I have made a video tutorial to company this series so if you would like to check it out.
hope you enjoyed this tutorial and as always happy coding!