Deploy Your Website Using a Virtual Machine

This guide will walk you through setting up a website using a virtual machine. We will cover how to create a virtual machine, configure it and deploy live updates.

I used Azure web services for this demo, which is admittedly not the friendliest service on the market. However, this guide can apply broadly to setting up VM's on a number of different providers.

Creating a Virtual Machine

  1. Login to the Azure management portal.
  2. Select VMs / New / From Gallery
  3. Select a Ubuntu server image (Ubuntu Server 14.04 LTS is the latest).
  4. Specify a vm_name and username and check the box to specify a password. You can uncheck the SSH Key box.
    IMPORTANT: You will need to remember these items!
  5. Azure will start creating your virtual machine. This can take a few minutes to complete.

Configuring Your Virtual Machine

  1. Once your VM has been created login to it form the command line (these are the items you specified above):
    ssh <username>@<vm_name>

  2. You'll then be prompted for the password you created above. Enter it and you'll have access to your VM.

  3. Follow this awesome guide to install homebrew on your VM. This package will also install some utilities like git on your VM.
    IMPORTANT: Make sure to navigate to the .bashrc and enter the specified lines (brew will not be a recognized command until you do this). You will need to reboot the VM once you've completed these steps: sudo reboot.

  4. Intall node: brew install node

  5. Clone your project repo: git clone <HTTPS_clone_url>

  6. Navigate to your project directory and run the following commands to install your dependencies:

     npm install // Install server dependencies
     sudo npm install -g bower // Install bower command line utility
     bower install // Install client dependencies
     sudo npm install -g gulp // Use gulp or grunt for task automation
     gulp // Build app, run server and static server

Note: I'm assuming you'll be using a task automation service to build, compile and run your app. Gulp and grunt are both great services for task automation.

Once this process is complete your app should be up and running.

  1. Next you need to install forever, so you can continuously run your server:

     sudo npm install -g forever
     forever start <server_file>

To view a list of forever tasks running: forever list
To stop a task (use the index number of the task to stop): forever stop 0

  1. Your VM is configured. Go ahead and log out. The last thing you'll need to configure is your ports, so you can access your server and app (use any port numbers you like):

     // Set-up server port
     azure vm endpoint create-multiple <vm_name> 8000:8000
     // Set-up client port (if necessary)
     azure vm endpoint create-multiple <vm_name> 9000:9000

Deploying Updates

  1. Once the you have new changes to deploy, login to your VM.

  2. From your project directory pull down the changes: git pull origin master

  3. Run the following commands to install new dependencies and build your app:

     npm install
     gulp  // or grunt depending on your automating service.
  4. Finally restart your forever server:

     forever stop 0
     forever start <server_file>