LAMP 2019Open SourceVirtualization

Setup VM – Building a LAMP Server (2019)

This covers setting up a Virtual Machine (VM) for use as a LAMP server for testing purposes.

I chose VirtualBox because it is free in most cases and runs on many platforms. 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. If your host operating system is Windows, be sure to uninstall Hyper-V (if it is installed) before configuring VirtualBox or just stick with Hyper-V. I’ve had conflicts between the two.

VirtualBox is a type-2 hypervisor, which means it runs as a client under your host operating system, which will affect performance. I recommend it for testing purposes, but not for production use. For a production server, you will want to use a type-1 hypervisor like Hyper-V (free if you have Windows Pro or Server), Linux KVM, VMWare ESXi, or XEN.

Important: as of version 6.0, VirtualBox will no longer run on a 32-bit host (though it should still be fine for 32-bit guests). So if your host operating system is only 32-bit, you will need to install 5.2 instead. Though given the RAM limitations of 32-bit operating systems, you probably shouldn’t be installing VirtualBox on one anyway.

Estimated time (this post only): 5 minutes

Choose your host operating system from the tabs below. I will assume your host OS contains a desktop environment (like Windows 10, Gnome, KDE, etc.).

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. This is a straight-forward process. Just follow the bouncing ball (metaphorically).

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

You can follow the instructions on the CentOS wiki here but my method below doesn’t install as many unnecessary packages.

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-6.0

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:"

CentOS 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 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-6.0

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:"

Fedora 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.

Although Ubuntu offers fairly recent versions of VirtualBox, to get the most recent you should use the following method. Note that when a new version of Ubuntu is released, there are usually a few days before the VirtualBox repos update, so if you have recently upgraded you may need to compile from source instead, or replace "$(lsb_release -sc)" with the name of the previous version like "bionic" instead of "cosmic".

Open a terminal and do the following:

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

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

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
sudo apt update
sudo apt install gcc make dkms linux-headers-$(uname -r)
sudo apt install virtualbox-6.0

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "sudo apt install linux-headers" rather than "sudo apt 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

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. Depending on your desktop environment, the link to VirtualBox should now be easily accessible (just click "Activities" and type "virtual" in Gnome for example).

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.d/virtualbox.list'

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

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
apt update
apt install gcc make dkms linux-headers-$(uname -r)
apt install virtualbox-6.0
exit

If something goes wrong, you most likely didn’t install the correct kernel headers (i.e. you ran "apt 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:

su
/sbin/vboxconfig

You can now find it in "Applications -> System" (if using the LightDM desktop environment).

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.

First, open Konsole and do the following to get some prerequisites:

sudo zypper install lsb wget

For older versions of openSUSE Leap, now do:

sudo zypper ar -f http://download.virtualbox.org/virtualbox/rpm/opensuse/$(lsb_release -sr)/virtualbox.repo

As of this writing, there is no repo file for openSUSE Leap 15.0 (and possibly newer versions), so the above command will fail. Instead, do:

sudo zypper ar -f -n virtualbox http://download.virtualbox.org/virtualbox/rpm/opensuse/$(lsb_release -sr)/x86_64/ virtualbox

For Tumbleweed, chances are you won’t be able to find an RPM compatible with your version as Tumbleweed is a rolling release, so the above doesn’t apply to you. More on this in a minute.

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_15.1/ packman
sudo zypper ar -f -n packman ftp://ftp.links2linux.de/pub/packman/suse/openSUSE_Leap_15.0/ 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-6.0

If using Tumbleweed, the last command will most likely fail, so instead do the following which may or may not install the latest version of VirtualBox (if you need the latest version for Tumbleweed, you will need to build from source and I won’t cover that here):

sudo zypper install virtualbox

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 Gnome), 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 via "File" -> "Preferences" -> "Extensions".

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:

Create a CentOS VM

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. More RAM may help performance, and you will need more disk space if you plan to keep all the source files. You will need even more resources if you plan to install a desktop. For a minimalistic LAMP server (a single database engine for example), you can get away with much less. I wanted to install absolutely everything and my host machine had 64 GiB of RAM and terabytes of free disk space, so resource allocation wasn’t an issue, thus I did the following:

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.