Skip to content

Instantly share code, notes, and snippets.

@mosufy
Last active August 29, 2015 14:06
Show Gist options
  • Save mosufy/c46c89a2472450681de9 to your computer and use it in GitHub Desktop.
Save mosufy/c46c89a2472450681de9 to your computer and use it in GitHub Desktop.
Setup Local Development Server Environment (LEMP on VirtualBox)

Setup Local Development Server Environment

Be sure to have VirtualBox Setup and LEMP Stack installed on it before proceeding. Also ensure your guest (VirtualBox) have access to host's (your computer) Shared folder (You can find the instructions on VirtualBox Setup Guide.

Pre-requisite: Shared Folders Setup

Having a Shared Folder will allow your guest (the VirtualBox) access to any folders on your host. A simple use case is to allow your local development folder access to guest. Simply change the files on this folder to update your web app. This step is optional but is highly encouraged.

Step 1. Declare shared folder (on Host machine)

  1. Create a folder on Host machine
  2. On Oracle VirtualBox, Click Settings > Shared Folders
  3. Add a new shared folder definition on Machine Folders
  4. Select the folder path
  5. Name the shared_folder
  6. Make permanent > OK

Step 2. Install VirtualBox DKMS

DKMS is required in order to run guest additions

$ sudo apt-get install virtualbox-guest-dkms

Step 3. Install VirtualBox Guest Additions

$ sudo apt-get install virtualbox-guest-additions-iso
$ sudo reboot

Step 4. Mount the shared folder (on Guest machine)

$ sudo mount -t vboxsf `shared_folder` /var/www

This will share shared_folder to nginx's /var/www folder (since this is where all our webapp folders will reside).

Check if mount is successful.

$ cd /var/www

Congrats! You should be able to find the same files as that of your Host shared_folder. ANy changes you do on your Host machine shared folder will not be reflected on Ubuntu as well.

Tip!

To automatically mount the same folder after each boot, edit /etc/rc.local and add the mount command before exit 0.

$ sudo nano /etc/rc.local

...
mount -t vboxsf shared_folder /var/www
exit 0
...

The next step is to configure a local domain name to point to your guest's ip address.

Step 1. Configure host machine

Find your host's "host" file. Open the file using any text editor (Notepad, etc.) as Administrator.

C:\Windows\System32\drivers\etc\hosts

Type the IP address of your guest machine with a local domain name. I'd usually add a .dev extension to indicate a local dev environment like domain_name.dev.

192.168.1.X   domain_name.dev

Step 2. Setup server block on guest machine

Instructions to creating a server block can be found here > LEMP Stack Installation Guide.

Just have to change the server_name to the domain_name.dev that you have just created.

Step 3. Test virtual host

Next, create a file on /var/www/domain_name/public/ to test if you have it setup correctly.

$ sudo nano /var/www/domain_name/public/index.php

...
<?php
  echo 'Hello World';
  exit;
?>
...

Go to domain_name.dev on your browser and you should be able to see "Hello World" printed. Have fun!

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