Skip to content

Instantly share code, notes, and snippets.

@mosufy
Last active August 29, 2015 14:06
Show Gist options
  • Save mosufy/625e089d59ae3e4fa147 to your computer and use it in GitHub Desktop.
Save mosufy/625e089d59ae3e4fa147 to your computer and use it in GitHub Desktop.
Create your own virtual linux box on your current OS Windows

VirtualBox Setup Guide

A VirtualBox is the best way to allow for local development for your web projects. Easily mimic an exact replica of your actual physical remote servers (or that of any cloud hosting providers) and test out your development frameworks before pushing it to your production or staging environments.

Warning: This guide is only meant to serve local installation of a virtual machine and not meant for 'live' or remote actual servers.

VirtualBox Setup

  1. Download and Install VirtualBox from Oracle website https://www.virtualbox.org/wiki/Downloads
  2. Run Oracle VM VirtualBox (VB)
  3. Click New >
  4. Name and Operating System > - Name: Ubuntu - LEMP - Type: Linux - Version: Ubuntu 64-bit
  5. Create Virtual Machine > Memory Size: 1024
  6. Hard Drive > - Create a Virtual Hard Drive now - Select VDI (VirtualBox Disk Image) - Select Fixed size (Recommended 8GB)
  7. File Location and Size leave default or adjust accordingly
  8. Once setup is complete, click Settings > Network
  9. Adapter 1: Attached to > Bridged adapter (will be assigned a local IP address to connect to)
  10. Adapter 2: Host-only adapter
  11. OK to save and close
  12. CONGRATULATIONS! Your Box is now ready to use! However, there this is an empty box as we have not yet installed any OS.

Ubuntu Installation

We will not install an Ubuntu Server 14.04 LTS.

  1. Download the ISO of the OS. For Ubuntu Ubuntu Server 14.04.1 LTS > http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-server-amd64.iso
  2. Select the newly created VM
  3. Click Settings > Storage
    1. Controller > IDE
    2. Select the downloaded OS ISO. This will boot the ISO on machine power on
  4. OK to save and close Settings
  5. Click Start to power on VB. You will be taken to a series of installation wizard
  6. Installation Wizard >
  7. Language > English
  8. Select Install Ubuntu Server
  9. Detect keyboard layout > No
  10. Partition Disks > Guided - Use entire disk
  11. Software selection > Manual package selection
  12. Install GRUB boot loader > Yes
  13. Login with the account and password as per setup
  14. Update the apt sources list. This list contains all the packages that Ubuntu will fetch. If you're like me, most of the time the Singapore server will be down. Hence we would like to change the source server to that of the main one.

Open the apt-sources list.

    $ sudo nano /etc/apt/sources.list

Look through the list and comment out all deb-src like so.

    $ #deb-src http://...

Only do this step when you fail to do an apt-get update. Change all deb http://sg.archive.ubuntu.com/... to deb http://archive.ubuntu.com/...

    $ deb http://archive.ubuntu.com/...

Effectively we are trying to change our source server to that of the main instead of the local country's server. 9. Update Ubuntu to the latest patch

    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo reboot
  1. That's it! Ubuntu Server has been successfully installed and updated!

TIP: At this point, take a snapshot of the server by clicking Machine > Take Snapshot. Snapshots produces exact-image-copy that allows you to easily re-create another instance of the machine in case of failure or for easy replication. Think of it like a backup carbon-copy of your server instance.

Assign Static IP

In order for you to access VB, you would need to assign an ip address. This step is not necessary as the host will automatically assign it an ip address though this might change every time.

By following this step, you will be assured that VB will always be assigned the same static ip address as you have defined.

  1. Edit /etc/network/interfaces (where X is your preferred digit)

     $ sudo nano /etc/network/interfaces
     ...
     
     # This file describes the network interfaces available on your system
     # and how to activate them. For more information, see interfaces(5).
     
     # The loopback network interface
     auto lo
     iface lo inet loopback
     
     # The primary network interface
     auto eth0
     iface eth0 inet static
       address 192.168.1.X       # Assign any IP address (1 - 250)
       netmask 255.255.255.0     # Check router for the default netmask
       gateway 192.168.1.254     # Check router for the default gateway
       dns-nameservers 8.8.8.8   # This is to reference itself (Ubuntu)
     ...
     
     $ sudo reboot
    
  2. Do an ifconfig to confirm the new ip address assigned.

     $ sudo ifconfig
    

LEMP Installation

Now that Ubuntu server is up and running, you may begin to install any software you desire. For this tutorial, we will specifically install LEMP stack (Linux, Nginx, MySQL, PHP). Nginx has taken over Apache in terms of usage growth and will be the server of choice for future developers. Read more about nginx to learn more.

  1. Install nginx

     $ sudo apt-get update
     $ sudo apt-get install nginx
    
  2. Check if nginx is installed properly. Go to ip address as set earlier. You should see a message with "Welcome to nginx". That's it!

For a more detailed installation guide to Installing LEMP Stack, please see this gist: LEMP Stack Installation Guide > https://gist.github.com/mosufy/ee5094a791097b1006c6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment