Building LAMP Server #2 – Setting Up VM

For development purposes, it is highly recommended that you use a virtual machine. For this article I will cover installing VirtualBox on a Windows or Linux host. If you plan to install your LAMP stack on an existing VM or other platform, you can skip this article and continue to the next.

Estimated time (this post only): 5 minutes

Choose your host operating system from the tabs below. For the purposes of this article I will assume your host OS is not a headless installation and includes a full desktop.

Installing VirtualBox

If you’ve ever installed software under Windows (and I assume you have), this is simple. Just download and install VirtualBox on your host machine if it isn’t installed already. This is a straight-forward process so I won’t bore you with the details.

See below for further instructions not dependent on your host OS.

First you need to install a few prerequisites. Launch the terminal and do:

sudo yum install gcc make

Find out what kernel version you are running so you can install the correct headers:

uname -r

This should output something like:

3.10.0-514.el7.x86_64

Now install the headers for your kernel by running the following (change version as needed):

sudo yum install kernel-devel-3.10.0-514.el7.x86_64

Now add the Oracle VirtualBox repo file to your list of sources for package management:

cd /etc/yum.repos.d
sudo wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
sudo yum install VirtualBox-5.1

(You may need to change the VirtualBox version number to whatever the latest is.) If you followed the above steps, everything should go smoothly. If something goes wrong, you most likely didn’t install the correct kernel source (i.e. you took a shortcut and ran "sudo yum install kernel-devel" while not booted up to the latest kernel). You can run the VirtualBox configuration with the following command to see what errors it encountered:

sudo /sbin/vboxconfig

Once complete, you should be able to find VirtualBox under the "System Tools" section:

See below for further instructions not dependent on your host OS.

First you need to install a few prerequisites. Launch the terminal and do:

sudo dnf install gcc make

Find out what kernel version you are running so you can install the correct headers:

uname -r

This should output something like:

4.8.6-300.fc25.x86_64

Now install the headers for your kernel by running the following (change version as needed):

sudo dnf install kernel-devel-4.8.6-300.fc25.x86_64

Now add the Oracle VirtualBox repo file to your list of sources for package management:

cd /etc/yum.repos.d
sudo wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
sudo dnf install VirtualBox-5.1

(You may need to change the VirtualBox version number to whatever the latest is.) If you followed the above steps, everything should go smoothly. If something goes wrong, you most likely didn’t install the correct kernel source (i.e. you took a shortcut and ran "sudo dnf install kernel-devel" while not booted up to the latest kernel). You can run the VirtualBox configuration with the following command to see what errors it encountered:

sudo /sbin/vboxconfig

Once complete, you should be able to find VirtualBox under "Activities:"

See below for further instructions not dependent on your host OS.

Although Ubuntu does offer fairly recent versions of VirtualBox, to get the most recent you should use the following method. Launch the terminal and type the following:

sudo gedit /etc/apt/sources.list

At the end of this file add the following line, then save and close GEdit. Change "zesty" to match your distribution/version (this is correct for Ubuntu 17.04):

deb http://download.virtualbox.org/virtualbox/debian zesty contrib

You can now install VirtualBox from the terminal with (change version number to match most recent version of VirtualBox):

sudo apt-get update
sudo apt-get install dkms virtualbox-5.1
virtualbox

That last command is needed to start VirtualBox because Ubuntu won’t add it to the Dash automatically. Now you can do so by right-clicking its icon in the Launcher.

See below for further instructions not dependent on your host OS.

The default Debian sources do not maintain current versions of VirtualBox, so let’s install from the official source. Launch the terminal and type the following (note that I’m assuming this is a default installation without sudo configured):

su
gedit /etc/apt/sources.list

At the end of this file add the following line, then save and close GEdit. Change "jessie" to match your distribution/version (this is correct for Debian 8.8.0):

deb http://download.virtualbox.org/virtualbox/debian jessie contrib

You can now install VirtualBox from the terminal with (change version number to match most recent version of VirtualBox):

apt-get update
apt-get install dkms virtualbox-5.1

You can now find it in "Activities:"

See below for further instructions not dependent on your host OS.

As of this writing, openSUSE contains the current version of VirtualBox in the default repos. So just look at the following screenshots for what to do:

See below for further instructions not dependent on your host OS.

As of this writing, the default Arch Linux installation provides sources for Pacman with the latest version of VirtualBox. So, assuming you have correctly configured your network settings and a desktop environment (I tested this with Gnome), you should be able to launch the terminal and perform the following steps:

pacman -S linux-headers
pacman -S dkms virtualbox

You should now be able to find VirtualBox in "Activities:"

See below for further instructions not dependent on your host OS.

Install Extension Pack

On your host OS, open your preferred web browser and download the extension pack. Depending on your OS/browser, you may be given the choice of opening the file directly in VirtualBox; if so, choose this option. Otherwise just download to your regular download directory and install it with VirtualBox:

Setup Virtual Machine

Once installed and running, click the "New" button to create your new VM and follow the steps. VirtualBox will choose appropriate minimum settings based on the name you give the VM as in the following screenshot:

Creating a CentOS 64-bit machine

How much RAM and disc space to allocate to your VM depends on how much in this guide you intend to install. If you want to install absolutely everything and have all the databases running simultaneously, 2 GiB RAM and a 50 GB HDD are the absolute minimum required (possibly much more for smooth performance, especially if you plan to keep all source files). You will need more if you plan to install a desktop on your VM. Less if you are only going to install a single database. In my case, my rig had 64 GB of RAM and over 20 TB of disk space, so I was able to allocate plenty of resources to the VM:

By default, VirtualBox will setup the virtual machine with a single NAT network adapter. This is the simplest method of allowing a VM to access the Internet, but your host system will not be able to easily access the VM. I recommend setting up a second "Host-only adapter." This way you can use tools like SSH from your Windows host to manage the VM (alternately you could setup a single adapter using bridged mode, but that can be a bit more complicated):

That’s it! That should be all you need to prepare your VM for installing any standard Linux distro. In the next article we will cover installing the operating system.

Leave a Reply