Minimal LAMP Stack for Website Development

By Jimmy Bonney | February 17, 2013

Lamp

Recently, I needed to have a LAMP (Linux, Apache, MySQL, PHP) environment in order to test out a few things for a website that was developed using nanoc but included a few dynamic PHP pages. While nanoc is mainly for static website, it is however flexible enough to include dynamic pages if one feels like it. The problem in this case relies in testing those dynamic components.

Even though I am using Linux on a daily basis, I didn’t deem appropriate to install a full LAMP stack just for the purpose of testing out a couple of pages. I therefore looked into some solutions providing a virtual LAMP stack that could then run inside a virtual machine - allowing me to do the development on the host system and test it on the guest one.

Download LAMP stack

The following assumes that you have VirtualBox installed and running. On Ubuntu, this can be done easily with a sudo apt-get install virtualbox.

Go to the TurnKey Linux LAMP Stack page and download the Virtual Machine (direct link). The distribution is based on Debian and comes with a few additional tools and packages installed by default. When this is done, move the virtual machine to the folder of you choice and unzip it.

Create a VM in VirtualBox

Start VirtualBox and launch the assistant to create a new VM.

New virtual machine wizard

Give a name to the new VM.

Virtual machine name

Define how much memory the VM will be allowed to used.

Virtual machine memory

In the virtual hard disk panel, select the option “Use existing hard disk” and select the TurnKey file that you have downloaded and unzipped (file.vmdk).

Turnkey Linux virtual machine disk

The final step is to confirm the setting and create the VM.

Virtual machine confirmation

Configure the VM

The new VM should be available in the list of VM. Before launching it, we’ll make sure that the settings are correct. Select the VM and click on the “Settings” button.

In the System menu, go to the processor tab and activate the “EnablePAE/NX” option.

Virtual box enable PAE

In the Network menu, enable one of the adapters and ensure that it is attached to Bridged Adapter. This will allow the VM to receive an email address on the network on which your Host is (which is important to be able to access the VM web interface directly from the host).

Virtual box bridged network

Do not configure any shared folder yet. At a later stage, we’ll make the necessary configuration so that the output folder of the nanoc website is shared between the host and the guest so that once the website is compiled on the host, it can be accessed on the guest.

TurnKey Linux configuration

Start the VM and follow the instruction provided on screen.

Define a root password for the appliance and the MySQL Database.

TurnKey Appliance root password

TurnKey Appliance mysql root password

If you use TurnKey Backup and Migration and / or TurnKey Domain Management tools, you can enter you API key, otherwise skip this step.

TurnKey Appliance backup

It’s always best to install the lastest security updates, so go ahead with that.

Turnkey appliance security update

Once completed, the VM should provide you the necessary information to access it through the web browser or SSH.

TurnKey appliance configuration settings

And from the host, it is then easy to access the admin interface.

TurnKey Admin Interface

Share folder between Host and Guest

Install guest additions

In order to be able to share folders between the host and a guest, VirtualBox requires the package guest additions to be installed. If you are using Ubuntu, once again the process is pretty straightforward with a sudo apt-get install guest-additions. If not, it is possible to download the correct guest additions based on your version of VirtualBox directly on VirtualBox website.

In this section, we’ll mainly follow the TurnKey guide to mount shared folder. Start a console on the host and connect using SSH to the guest.

1
ssh root@IP #provide the IP from the screenshot above

Once connected to the guest, launch the following commands:

1
2
apt-get update
apt-get install dkms build-essential linux-headers-$(uname -r)

Once this is completed, if guest additions have been properly installed, you should see a menu items called ‘Devices’ and a menu entry called ‘Install Guest Additions…’. If so, click on it and go directly to the section below entitled ‘Install guest additions automatically’. If not, keep reading.

Install guest additions manually

If you read this section then you do not see a menu entitled Devices when you select the VM containing the LAMP stack. In such case, start by turning off the VM. You can do so by going to the Advanced Menu and select the shutdown option.

TurnKey appliance advanced options

From the VirtualBox Manager, select the LAMP VM and click on the Settings buttons and go to the Storage menu and click on the Add CD/DVD Device. In the dialog that pops up, select Choose Disk and find the guest additions ISO that you have downloaded. The ISO will then be available when you restart the VM under /dev/cdrom or /dev/cdrom1 depending on whether you have multiple CD devices or not.

VirtualBox add CD device

Install guest additions automatically

In the best case scenario, the guest additions have been installed and are recognized globally so that there are available through the Devices menu. In such case, simply click on the ‘Install Guest Additions…’ menu item. This doesn’t actually do any installation. It just mount the virtual CD so that it becomes accessible on the guest. We continue following the guide in this section.

Still using the SSH connection established with the guest, we mount the CD image.

1
mount /dev/cdrom /mnt

If the you receive a message stating that a format needs to be specified, then you can use the following command instead:

1
mount -t iso9660 /dev/cdrom /mnt

Now, if you used the manual procedure to load guest additions, you might have multiple CD devices and might need to use cdrom1 instead of cdrom in the command above. Once it is mounted, simply continue with:

1
2
cd /mnt
./VBoxLinuxAdditions.run --nox11

This last command might take some time and as mentioned in the guide you can safely ignore the following error message:

1
2
Installing the Window System drivers ...fail!
(Could not find the X.Org or XFree86 Window System.)

At this stage, we are ready to share folders between the host and the guest.

Add shared folder

Adding a shared folder is pretty easy. Simply go to the menu Devices > Shared Folders… or from the VirtualBox Manager, select the VM and click the Settings button and select the menu Shared Folders.

VirtualBox add shared folder

You can select here the folder containing the website that you would like to test in the virtual environment. In my case, this is the output folder generated by nanoc. If the folder was added while the VM was running, then it is necessary to restart it so that the folder is properly loaded. Once the appliance has restarted, you can see the list of shared folder directly by running:

1
mount | grep vbox

In my case, the result of the command is something like:

1
website on /media/sf_website type vboxsf (gid=1001,rw)

And one can see the list of shared files with

1
ls -l /media/sf_website

Conclusion

Setting up a LAMP server is pretty easy as many tools have been developed and allow to deploy a virtual machine in a few minutes of work. The next article will focus on setting up Apache in order to use the shared folder as one of Apache directory so that it can be accessed right away from the host web browser.



comments powered by Disqus