With the release of Ubuntu 16.04 LTS, PHP 7 and MySQL 5.7, much of the information out there about setting up a LAMP stack on VirtualBox has started to become obsolete. This tutorial will explain the entire process from start to finish using the latest software and is split up into 4 separate articles, or parts:
Part 1: Installation
- Why Use VirtualBox?
- Host and Guest
- Download and Install the Necessary Software
- Create a New Virtual Machine in VirtualBox
- Modify Virtual Machine Settings
- Install Ubuntu
Part 2: Setup LAMP Stack
- Install Apache
- Install MySQL 5.7
- Install PHP 7
- Restart Apache
- Prepare the WWW Directory
- Install phpMyAdmin
Part 3: Access Guest From Host
Part 4: Ubuntu Customization
Why Use VirtualBox?
- Linux! Linux is the preferred environment for web development. Even though OS X is Unix-based and WAMP is a viable option for developing in Windows, neither are the same as working directly in Linux.
- Portability! Imagine you have 2 computers (and many of you probably do)... one is a Mac and the other is a Windows PC. You can setup a complete development environment on each computer just by installing VirtualBox on each computer and copying over the virtual machine file.
- Consistency! Any computer I setup a development environment on will have the same exact configuration, thanks to its portability mentioned above. It follows the DRY principle of not having to repeat yourself.
Host and Guest
From here on out, Host refers to your computer (Mac) and Guest refers to your virtual machine (Ubuntu in VirtualBox).
Download and Install the Necessary Software
Download and install VirtualBox.
Download Ubuntu 16.04 LTS 64-bit and save it for later.
Create a New Virtual Machine in VirtualBox
Open VirtualBox and click New to start creating a new virtual machine.
Name and operating system
- Create a unique 'Name' for your virtual machine. In this example, I named it "MyDev".
- Select "Linux" for the 'Type'.
- Select "Ubuntu (64-bit)" for the 'Version'.
- Set the amount of RAM you want allocated. Notice the recommended amount is 768 MB, but it doesn't hurt to select more. I prefer 2048 MB.
- Choose "Create a virtual hard disk now".
Hard disk file type
- Select "VDI (VirtualBox Disk Image)".
Storage on physical hard disk
- Select "Dynamically allocated". You could set a fixed size, but you could end up wasting space. By choosing a dynamic drive, it will start at 8 GB and grow as needed.
Screen 6 - File location and size
- Leave the location set to "MyDev".
- Keep the 8 GB recommendation.
That completes the initial creation. Now let's change some settings.
Modify Virtual Machine Settings
Select your new virtual machine and click Settings
In the General tab under Advanced, change the following settings:
- Set 'Shared Clipboard' to "Bidirectional" so you can copy and paste between your host and guest.
- Set 'Drag-n-Drop' to "Bidirectional" to you drag and drop files between your host and guest.
In the Display tab under Screen, slide Video Memory all the way up to 128 MB.
In the Network tab,change the following settings:
- Under Adapter 1, leave 'Attached to' set to "NAT". This will allow your guest to access the internet.
- Under Adapter 2, check 'Enable Network Adapter' and change 'Attached to' set to "Host-only Adapter". This will provide a virtual, private network between your host and guest. More on that later.
That completes additional virtual machine settings. We're now ready to install Ubuntu.
Select your new virtual machine and click Start.
Select the iso file you downloaded earlier and click Start.
Once Ubuntu boots up, select your language and click Install Ubuntu.
Preparing to install Ubuntu
- Check 'Download updates...' and 'Install third-party software...' and click Continue.
- select 'Erase disk and install Ubuntu' and click Install Now.
- When prompted to confirm the disk changes, click Continue.
Where are you?
- Select your geographical region and click Continue.
- Select your preferred keybpard layout and click Continue.
Who are you?
- Enter 'Your name'. For consistency, I kept it "MyDev".
- Set the computer name to a lowercase instance of 'Your name'.
- Again, for consistency, I made the username the same as 'Your computer's name'.
- Enter a password. Since you'll be the only one with access to Guest, you could keep it simple.
- Select 'Log in automatically'.
Once installation is complete, you'll be asked to restart. Click Restart Now.
Next you'll be asked to remove the installation disk. Since there is not disk, just press ENTER.
Congratulations! You now have a fully functional Linux operating system running on VirtualBox.
Next, we'll setup the LAMP stack.