Set up a LAMP Stack with Linux and VirtualBox

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.

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

- Give the setup a name.
- Choose “Linux” as the Type.
- Choose “Other Linux” for the Version.

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.

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.


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.

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

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.


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.

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.

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

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.

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!

Thanks, this was exactly what i was looking for….
You are welcome John.
great , but if we need access with ftp, how work ?
Hi tmex,
FTP to what the local dev ? You should be fine just dropping the files in the correct place you can install filezilla for linux if you want a FTP client that is similar to windows.
Great article, thanks. I realize I am commenting 7 months later, but wouldn’t PHP 7 be the version to install, instead of PHP 5?
Hi Steve,
Yes I would definitely recommend PHP7
Hi Daniel,
I am following along in setting up LAMP stack and I was at the point where I am trying to create the
test.php file. Add your command and get this error when trying to save the file.
Error writing /var/www/html/test.php: No such file or directory
I am thinking its a permissions thing. Any ideas how to overcome this problem?
Trying doing it while logged in as root should confirm if it is it a permissions issue. Once you confirm it you can set the permissions for the folder. sudo chown -R YourUserNameHere /var/www/html
Not really sure what happened, Apparently, I needed to re-install apache2. All is working.
Great work. Least you figured it out.
thanks , but it was more interesting if you create a virtual machine from a server version of Linux as guest machine and accessing it from host machine 🙂
Hi Mostafa,
That really would be overkill. You just need to SSH, rysnc or use git to push pull changes to a server
anyone doing this now and experiencing php not parsing – try installing the libapache2-mod-php7.0 (if using php7 obviously)