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
- Login to the Azure management portal.
- Select VMs / New / From Gallery
- Select a Ubuntu server image (Ubuntu Server 14.04 LTS is the latest).
- Specify a
usernameand check the box to specify a
password. You can uncheck the SSH Key box.
IMPORTANT: You will need to remember these items!
- Azure will start creating your virtual machine. This can take a few minutes to complete.
Configuring Your Virtual Machine
Once your VM has been created login to it form the command line (these are the items you specified above):
You'll then be prompted for the password you created above. Enter it and you'll have access to your VM.
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
.bashrcand 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:
brew install node
Clone your project repo:
git clone <HTTPS_clone_url>
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.
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:
To stop a task (use the index number of the task to stop):
forever stop 0
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
Once the you have new changes to deploy, login to your VM.
From your project directory pull down the changes:
git pull origin master
Run the following commands to install new dependencies and build your app:
npm install gulp // or grunt depending on your automating service.
Finally restart your forever server:
forever stop 0 forever start <server_file>