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.
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.
- Create a folder on Host machine
- On Oracle VirtualBox, Click Settings > Shared Folders
- Add a new shared folder definition on Machine Folders
- Select the folder path
- Name the
shared_folder
- Make permanent > OK
DKMS is required in order to run guest additions
$ sudo apt-get install virtualbox-guest-dkms
$ sudo apt-get install virtualbox-guest-additions-iso
$ sudo reboot
$ 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.
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.
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
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.
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!