Set up a LAMP Stack with Linux and VirtualBox

In this tutorial, I'm going to show you how to set up a LAMP stack inside a Windows container.

Recently, an OSTraining member was moving from Windows to Linux. They wanted help to set up their development environment and I recommend VirtualBox.

With VirtualBox, you can set up a development environment in under an hour and it will run flawlessly.

We're also going to use Linux Mint in this tutorial. These steps work with Ubuntu also, but Mint has a slightly easier interface, particularly for Windows users.

Getting started with VirtualBox

Go to the VirtualBox website and download the VirtualBox for your OS. you will also need to download the ISO for Linux. For the purpose of this tutorial, we will be using the Mint 64bit Cinnamon.

Getting started

Once VirtualBox is completed you will see the screen below. We need to choose "New" from the top-left menu.

Install VirtualBox
  • Give the setup a name.
  • Choose "Linux" as the Type.
  • Choose "Other Linux" for the Version.
Configuring the container

Here you have to decide how much free RAM you can dedicate to your setup. You can see that it only wants 512MB, but any extra RAM you can assign will help the setup run quicker. Personally, I set this to 2000 MB.

Setting memory dedicated to your virtualbox

You now have a choice of options for your virtual machine hard drive. I recommend creating a virtual hard drive as it tends to operate better. Plus, if you remove this later, it won't leave any redundant files hanging around. The next screen will give you a choice of virtual disks. Using the default is recommended.

Configuring your hard drive for virtualbox
Now we configure how the virtual drive will operate. I recommend leaving the drive as a "Dynamically allocated" so you don't have to worry about wasting space. On the following screen, you can choose how much space you want to assign by default. 8 gig is the amount allocated and since the drive will adjust as needed you don't really need to change this.
Configure how the virtual drive will operate

Begin installing Linux Mint

Click "Start" and the VirtualBox will start. You will be prompted for the start-up disk: select the ISO file for linux that we downloaded earlier.

Begin installing mint

This is a livecd setup. To finish the installation, you need to choose to install Linux Mint. 

Completing installation

Using Terminal

Now that we have set up Linux, it's time to get used to using Terminal, which is the default way of issuing commands for Linux. 

Open Terminal from the menu bar and enter sudo apt-get install php5 mysql-server apache2.

Using Terminal
You will be asked to provide your password. Then select Y to continue.
Installing the LAMP stack

Checking the LAMP stack is working

Now go to your browser and enter localhost. You should see the screen below. Ubuntu and Mint both share repositories and this tutorial should work just as well for Ubuntu as it does for Mint. Now we know Apache is working.

Next, we need to check that PHP is working. Let's create the PHP test page.

Checking the LAMP stack is working

Go back to terminal and enter "sudo nano /var/www/html/test.php". 

Nano is a text editor we are going to use to make the test page. In the new screen enter <?php phpinfo(); ?> and holding control down press x and save the file. Now if we navigate to localhost/test.php we should see the configuration for PHP. If you see the image below then congratulaions - you have set up a Mint Linux development environment.

Making a php test page

Now that we have the LAMP set up, from time to time you will want to go directly to the folder to make changes. By default the primary user is not granted permissions to change files in this location, so we have to tell Mint who will control the folder and all subfolders. We do this with the following command: sudo chown -R daniel /var/www/html 

Changing ownership of the folder

Installing phpMyAdmin

Finally, we are going to install phpMyAdmin to make using MySQL easier.

Go to the phpMyAdmin page on the Linux Mint website. Simply click install. You will be asked to choose Apache and set a password.

Installing phpmyadmin

In your browser, navigate to localhost/phpmyadmin and you should see the screen below. You will have to login using root and the password you set for your phpMyAdmin.

Congratulations, you now you have a fully functional LAMP setup with phpMyAdmin!

Checking phpmyadmin is working

About the author

Daniel is a web designer from UK, who's a friendly and helpful part of the training community.