Setup VM – Building a LAMP Server (2019)

Post navigation

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.

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.

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.

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

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

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.

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:

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.