LAMP 2017Virtualization

Building LAMP Server – Setup Virtual Machine

This is the second article in a series on building the ultimate LAMP Server. We will cover setting up a Virtual Machine (VM) for use as our test server.

This focuses on VirtualBox on a Windows or Linux host. If you plan to install your LAMP stack on an existing VM, another hypervisor, or a physical machine, 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. I will assume your host OS is not a headless installation and includes a full desktop.

Installing VirtualBox

WindowsCentOSFedoraUbuntuDebianopenSUSEArch Linux

If you’ve ever installed software under Windows (and I assume you have), this is simple. 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 dkms kernel-devel-$(uname -r)

Add the Oracle VirtualBox repo to your list of sources for package management. Change the version number to match whatever the latest is.

sudo yum-config-manager --add-repo http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
sudo yum install VirtualBox-5.2

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "sudo yum install kernel-devel" rather than "sudo yum install kernel-devel-$(uname -r)"). To investigate errors, 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 "System Tools:"

Now add your user to the vboxusers group:

sudo usermod -a -G vboxusers $USER
groups $USER

Assuming that was successful, you must log off and back on for the change to take effect.

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 dkms kernel-devel-$(uname -r)

Add the Oracle VirtualBox repo to your list of sources for package management. Change the version number to match whatever the latest is.

sudo dnf config-manager --add-repo http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo
sudo dnf install VirtualBox-5.2

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "sudo dnf install kernel-devel" rather than "sudo dnf install kernel-devel-$(uname -r)"). To investigate errors, 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:"

Now add your user to the vboxusers group:

sudo usermod -a -G vboxusers $USER
groups $USER

Assuming that was successful, you must log off and back on again for the change to take effect.

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. At the time of my testing, there was no repo available yet for Ubuntu 17.10, but I suspect it will only be a matter of days before it is created.

Launch the terminal and type the following:

sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" >> /etc/apt/sources.list'

Install VirtualBox from the terminal with (change version number to match most recent version of VirtualBox):

sudo apt-get update
sudo apt-get install gcc make dkms linux-headers-$(uname -r)
sudo apt-get install virtualbox-5.2

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "sudo apt-get install linux-headers" rather than "sudo apt-get install linux-headers-$(uname -r)"). To investigate errors, run the VirtualBox configuration with the following command to see what errors it encountered:

sudo /sbin/vboxconfig

Ubuntu won’t add it to the Dash automatically. So launch it with the following command and right-click its icon in the Launcher.

virtualbox

Now add your user to the vboxusers group:

sudo usermod -a -G vboxusers $USER
groups $USER

Assuming that was successful, you must log off and back on again for the change to take effect.

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

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

su
sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" >> /etc/apt/sources.list'

Install VirtualBox from the terminal with (change version number to match most recent version of VirtualBox):

apt-get update
apt-get install gcc make dkms linux-headers-$(uname -r)
apt-get install virtualbox-5.2
exit

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "apt-get install linux-headers" rather than "apt-get install linux-headers-$(uname -r)"). To investigate errors, run the VirtualBox configuration with the following command to see what errors it encountered:

sudo /sbin/vboxconfig

You can now find it in "Activities:"

Now add your user to the vboxusers group:

su -p -c 'usermod -a -G vboxusers $USER'
groups $USER

Assuming that was successful, you must log off and back on again for the change to take effect.

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

OpenSUSE contains newer versions of VirtualBox in the default repos. If that version is good enough for you, just follow the screenshots below (I will explain how to install from repo below):

Alternatively, to install a different version of VirtualBox, open Konsole and do the following:

sudo zypper install lsb wget
sudo zypper ar -f http://download.virtualbox.org/virtualbox/rpm/opensuse/$(lsb_release -sc)/virtualbox.repo

If the above command fails because you’re running a newer version of openSUSE, try the following:

sudo zypper ar -f http://download.virtualbox.org/virtualbox/rpm/opensuse/13.2/virtualbox.repo

Now add the Packman repo by running one of the following commands depending on your version of openSUSE:

sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_Tumbleweed/ packman
sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_Leap_42.3/ packman
sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_Leap_42.2/ packman
sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_Leap_42.1/ packman
sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_13.2/ packman

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

wget -q https://www.virtualbox.org/download/oracle_vbox.asc
sudo rpm --import oracle_vbox.asc
rm oracle_vbox.asc
sudo zypper install gcc make dkms kernel-source kernel-default-devel=$(uname -r | sed 's/-default*//g')
sudo zypper install VirtualBox-5.2

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "sudo zypper install kernel-default-devel" rather than "sudo zypper install kernel-default-devel=$(uname -r | sed ‘s/-default*//g’)"). To investigate errors, run the VirtualBox configuration with the following command to see what errors it encountered:

sudo /sbin/vboxconfig

You can now find it in the Application Menu under "System."

Now add your user to the vboxusers group:

sudo usermod -a -G vboxusers $USER
groups $USER

Assuming that was successful, you must log off and back on again for the change to take effect.

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 Cinnamon), you should be able to launch the terminal and perform the following steps:

sudo pacman -S linux-headers=$(uname -r | sed 's/-ARCH*//g')
sudo pacman -S dkms virtualbox

Now add your user to the vboxusers group:

sudo usermod -a -G vboxusers $USER
groups $USER

Assuming that was successful, you must log off and back on again for the change to take effect.

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/Linux host to manage the VM (alternately you could setup a single adapter using bridged mode, but that can be a bit more complicated, especially for laptops):

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