Setup a LAMP Stack with Mac/VirtualBox/Ubuntu - Part 1 of 4 - Installation

1st Oct, 2016 | Environments | Read Time: 4 mins

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

Part 2: Setup LAMP Stack

Part 3: Access Guest From Host

Part 4: Ubuntu Customization

Why Use VirtualBox?

  1. 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.
  2. 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.
  3. 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

  1. Open VirtualBox and click New to start creating a new virtual machine.

    Create New Virtual Machine

  2. 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'.

    Name and operating system

  3. Memory size

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

    Memory size

  4. Hard disk

    • Choose "Create a virtual hard disk now".

    Hard disk

  5. Hard disk file type

    • Select "VDI (VirtualBox Disk Image)".

    Hard disk file type

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

    Storage on physical hard disk

  7. Screen 6 - File location and size

    • Leave the location set to "MyDev".
    • Keep the 8 GB recommendation.

    File location and size

That completes the initial creation. Now let's change some settings.

VirtualBox Home

Modify Virtual Machine Settings

  1. Select your new virtual machine and click Settings

    Virtual Machine Settings

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

    General Settings

  3. In the Display tab under Screen, slide Video Memory all the way up to 128 MB.

    Display Settings

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

    Network Settings

That completes additional virtual machine settings. We're now ready to install Ubuntu.

Install Ubuntu

  1. Select your new virtual machine and click Start.

    Virtual Machine Settings

  2. Select the iso file you downloaded earlier and click Start.

    VirtualBox Install Linux

  3. Once Ubuntu boots up, select your language and click Install Ubuntu.

    Install Ubuntu

  4. Preparing to install Ubuntu

    • Check 'Download updates...' and 'Install third-party software...' and click Continue.

    Preparing to install Ubuntu

  5. Installation type

    • select 'Erase disk and install Ubuntu' and click Install Now.

    Installation type

    • When prompted to confirm the disk changes, click Continue.

    Confirm disk changes

  6. Where are you?

    • Select your geographical region and click Continue.

    Where are you

  7. Keyboard layout

    • Select your preferred keybpard layout and click Continue.

    Keyboard layout

  8. 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'.

    Who are you

  9. Once installation is complete, you'll be asked to restart. Click Restart Now.

    Restart

  10. Next you'll be asked to remove the installation disk. Since there is not disk, just press ENTER.

    Remove disk

Congratulations! You now have a fully functional Linux operating system running on VirtualBox.

Ubuntu desktop

Next, we'll setup the LAMP stack.

Comments

Leave a comment