LAMP 2020Open SourceVirtualization

Setup Virtual Machine – Building a LAMP Server (2020)

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

I chose VirtualBox because it is free and runs on many platforms. If you plan to install your LAMP stack on an existing virtual machine, another hypervisor, or a physical machine, you can skip this article. If your host operating system is Windows, be sure to uninstall Hyper-V (if it is installed) before configuring VirtualBox or stick with Hyper-V.

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, Linux KVM, VMWare ESXi, or XEN.

Important: VirtualBox 6.0+ will not run on a 32-bit host. 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): 30 minutes

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

Installing VirtualBox

WindowsCentOSFedoraUbuntu/DebianopenSUSEArch Linux

If you’ve ever installed software under Windows, this is simple. Download and install VirtualBox on your host machine. This is a straight-forward process.

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. You may need to update the kernel as follows:

sudo dnf update kernel

Restart then do the following:

sudo dnf install epel-release
sudo dnf install gcc make dkms kernel-devel-$(uname -r)

Add the Oracle VirtualBox repo and install. Change the version number to match whatever the latest is.

sudo wget -c -t 10 \
https://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo \
-P /etc/yum.repos.d/
sudo rpm --import https://www.virtualbox.org/download/oracle_vbox.asc
sudo dnf install VirtualBox-6.1

If something goes wrong, you most likely didn’t install the correct kernel headers. 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

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. You may be able to skip the update process, but it was necessary in my case. Launch the terminal and do the following.

sudo dnf install gcc make dkms kernel-devel-$(uname -r)
sudo dnf update

Reboot, then add the Oracle VirtualBox repo to your list of sources for package management. Change the version number to whatever the latest is.

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

If something goes wrong, you most likely didn’t install the correct kernel headers. 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:" or the Menu.

Now add your user to the vboxusers group.

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

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 (Debian does not) 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" (which may or may not work; if not use the version from the official repo).

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 as follows. Change version number to most recent version of VirtualBox.

wget -c -t 10 -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.1

If something goes wrong, you most likely didn’t install the correct kernel headers. 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

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 (click "Activities" and type "virtual" in Gnome for example).

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

Add the VirtualBox repo. The following worked for openSUSE 15.0 through 15.2.

sudo zypper ar -f -n virtualbox https://download.virtualbox.org/virtualbox/rpm/opensuse/15.0/x86_64/ virtualbox

For Tumbleweed, you may not 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.2/ 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 -c -t 10 -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.1

If using Tumbleweed, the last command may 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 may need to build from source.

sudo zypper install virtualbox

If something goes wrong, you most likely didn’t install the correct kernel headers. 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 "Applications" menu under "System."

Now add your user to the vboxusers group.

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

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

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

Now add your user to the vboxusers group.

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

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 virtual machine and follow the steps. VirtualBox will choose appropriate minimum settings based on the name you give the virtual machine as in the following screenshot.

Create a CentOS VM
Create a CentOS Virtual Machine

How much RAM and disc space to allocate depends on how much in this guide you intend to install. If you want to install everything and have all the databases running simultaneously, 4 GiB RAM and a 50+ GB HDD are the minimum required. More RAM may help performance, and you will need more disk space if you plan to keep all the source files. For a minimal 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.

Creating LAMP VM 1 Creating LAMP VM 2

VirtualBox will setup a single NAT network adapter. This is the simplest way to access the Internet, but your host system will not be able to easily access the virtual machine. 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 virtual machine. You could create a single adapter using bridged mode, but that can be a bit more complicated, especially for laptops.

VM NIC Setup 1 VM NIC Setup 2

That’s it! That should be all you need to prepare your virtual machine 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.