Vagrant Tutorial - Running a VM For Your Local Development Environment
Key Takeaways
Vagrant tutorial for creating a portable local development environment using Virtual Machines, mirroring staging and production environments for streamlined development workflows.
Full Transcript
so if you are at all passionate about server Administration or uh Dev Ops or making deployments uh or if you're wanting to get into that world uh vagrant and you don't know what vagrant is vagrant is awesome it is a tremendous tool for learning all that stuff basically what it does is it allows us to On Demand spin up virtual Linux boxes you could spin up four of them on your machine and run a you know run a load balancer and test failover stuff or you could spin up a virtual vagrant box and configure it and try to do deployments to that virtual machine it's a great playground for learning stuff and it's very useful for a lot of other things uh so let's go ahead and get into how to use vagrant to spin up a virtual Linux machine and later on once I'm done I'll kind of tell you some more philosophy on why you should use it for local development environment instead of wamp or M or stuff like that and how devs are using it but for now let's get into the fun stuff and let's actually use it you're going to want to go to vagrant up.com and you're going to want to download it you're also going to want to go to if you don't have virtual box installed yet virtualbox.org and download it and install it and all of this will by the way be in a gist that I will put in the description so I don't leave you hanging um and so those are both installed I should be able to go vagrant DV and you should be running 15 or newer uh for what we're going to be doing today so then all you have to do is go to vagrant cloud.com uh and we are going to pick some boxes that we want to install on our system so go to vagrant cloud.com and go to popular and the most popular ones are the precise 32 abunto box and the precise 64 uh 64 is more powerful but it's going to consume more RAM on your computer uh this precise 32-bit takes about 300 megabits of ram megabytes of ram to run and this takes more like 5 or 600 so I usually run the 32s unless I have a reason to run the 64-bit system cuz I can run a whole lot more of these especially if you only have like 4 GB of RAM or so you're going to want to run a 32bit uh so what you're going to do is vagrant box add and then that and that will download that box image it won't install anything on your system yet it's just going to put that box on your machine so we can now spin up you notice I've downloaded it before it'll take you a few minutes to download it if you have not um but now I can spin up as many precise 32 boxes as I want as long as my computer can handle it uh so now you're just going to go to you know install as many boxes as you want and now you go to the folder that you want to be running uh to actually create your virtual box in and you're going to go vagrant in knit and once again that um let me see if I can do no I can't Tab and have it auto correct uh hash cor precise 32 there we go so I'm going to now knit that um and now I can go vagrant up and so now I'm going to spin up my precise 32 box it's going to import the image it's going to start booting up my Linux box and it's also going to add a vagrant user and create SSH privileges for that user so I don't need a password um there we go now I'm running a Linux box on my machine so I can now go vagrant SSH and it's going to ssh in as my vagrant user so there we go I'm now on the precise 32 box as far as my computer's concerned this is a server out on the internet and I am sshing into it so I can go pseudo apt git install git I'm going to start installing GitHub on my new machine um that'll take a little while probably a minute or two so I'll cancel and pretend that was successful um so there we go I'm going to exit out now and let's go ahead and make this even more realistic let's give it an IP add address and a domain name uh so we can actually run it as a web server and as a fake uh domain name so we don't even need to purchase hosting uh let's go ahead if I LS I exit it out of that box and I'm back on my machine um and so what you can do now is let's go ahead and open that vagrant file in Sublime Text I'm going to change syntax to Ruby so it looks pretty okay so it created a vagrant configuration file for me and the only only line in it is this all the other ones are just kind of some boilerplate stuff for me and the only thing I'm going to add is I'm going to uncomment this private networking and I'm going to give it an IP address 55. 55.55 you can make up pretty much whatever you want um and so my IP address is going to be running that I'm going to save and quit and now I'm going to run vagrant reload so now it's going to uh re load my box with my new configuration it's going to shut my box down reboot it and now I'm going to be running you'll see that it is now making a connection to something it doesn't spin forever it makes a connection to something but it stops right away so it doesn't really know uh there's there's no Apache or there's no web server running on my Linux box uh so the connection goes through but I don't get an HTML file or anything so let's go ahead and install engine X let's go I'm going to vagrant SSH so I'm going back into my box if you're not familiar with engine X engine X is like a substitution for Apache uh usually it's what you use when you're running a node.js application in production we'll get into that in probably the next video um so let's go pseudo apt get let's update our apt get application real quick that's always a good idea whenever you spin up a box the first thing you should do is run aptg update um apt get install engine X so let's go ahead and install the engine X web server it's very light takes almost no time that's done and now all we have to do is go service we do pseudo service engine X start there we go it started and now if I run there we go welcome to engine X is my default so now I am running a web server on 55.55 55.5 now the only thing I want to do is I want to actually make this map to a domain name so let's go ahead and go we're going to go pseudo open Etc hosts uh and we're going to do this in I'll do in Sublime Text so here we are if you've never messed with a host's file before uh it's it's very basic there's basically just two rules don't change anything that's in here already um the other rule is any IP address you type in you can assign a domain name to it so now when anything on my machine goes to my awesom site.com it's going to send it to this IP address instead of whatever IP address it would normally send my awom site.com to I'm going to save it it may ask for your password um so now I should be able to go to mysite.com and there you go it's going to my new server welcome to engine X so what we've just done is we have spun up a Linux server you can now configure it however you want to um and you can then make sure that mysite.com goes to your server instead of whatever IP address you normally go to um and so what lots of times people will do is they'll actually do this is they'll go dev. awom site.com ask for my password and so then you'll go to dev. mysite.com for your local machine and then you'll go to my awom site.com for your production machine so I want to talk real quick about why you would do this two reasons one you want to play around with Linux machines and you want to be able to destroy them when you're done okay so that's that's a great reason right there um uh the other day I was running I think I already mentioned I was running you know tons of Linux machines behind a a fake Linux machine running a load balancer I was able to see what happens when memory started getting low on this machine and all these other things you can totally run tests you can set up a fake server and practice making command line deployments to that server without blowing up your production server um so there's that there's just practice and then the other big big big big big way that people are using vagrant is they are running a vagrant file in the repository for their project um and so what this is going to do is whenever your project is open you're going to be able to instead of running map uh which will install install Apache MySQL and PHP on your Mac uh or on your Windows machine you can actually just run a vagrant box that's configured exactly like your production web server and then you can give it an IP address and a domain name like dev. awesome website.com and so now you don't have your machine is not tied to one project uh cuz Lots of times what will happen is a Dev will have a problem on their machine uh but they're not seeing that problem on another dev's machine because they're running a different version of PHP or they're running a different version of Ruby or they're running a slightly different version of Mac OS 10 or something and this way the code you're writing is running on the exact same virtual box that all the other devs on your team are running their code on um uh another nice thing is that whenever vagrant makes that SSH connection you can actually access all the code from your repo right here from within the virtual machine so the virtual machine is running and it's running the code from your GitHub repository that you're editing on the machine you're on now if that makes any sense it basically solves the problem of well that doesn't happen on my machine why is it happening on your machine which happens to developers all the time so there's my Spiel there's my little Soap Box presentation for you I I hope you have a ton of fun with vagrant in the next video we're going to be getting into running um we're going to run a vagrant box and we're going to install engine X as a front end to our node.js application and then after that we're going to set up a load balancer so engine X can be running to multiple node.js servers uh and handling failovers and stuff like that hope you enjoyed the video
Original Description
Vagrant and VM's can RADICALLY shape your development workflow. Instead of every developer working on their own local server with their own configuration, you can configure a portable local environment that exactly mirrors your staging and production environments. Now developers can spin up this environment on their machine and work completely locally without having to change their machine configuration to accommodate the project they're working on. Also, each project they work on can have it's own VM running it's own configuration that they can spin up.
Also, Vagrant provides an easy-to-destroy environment to practice your Linux server administration skills!
Here's the Gist on how to follow along:
https://gist.github.com/learncodeacademy/5f84705f2229f14d758d
-~-~~-~~~-~~-~-
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
https://www.youtube.com/watch?v=fgOO9YUFlGI
-~-~~-~~~-~~-~-
Playlist
Uploads from LearnCode.academy · LearnCode.academy · 35 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
▶
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
Sublime Text Favorite Packages and Workflow
LearnCode.academy
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
Web Development Advice - Interview with Dev Tips
LearnCode.academy
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
Web Dev Training with Treehouse
LearnCode.academy
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy
🎓
Tutor Explanation
DeepCamp AI