Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Development with Virtual Machines

Web Development with Virtual Machines

Given the increasingly complex world of web development, there’s more to creating a website than just using a text editor and a browser. If you have to support multiple customers, possibly each with their hosting arrangements, it’s unlikely that your development machine will wholly reflect the setup of each host, and there might be conflicting software requirements (e.g. differing versions of PHP or Ruby, Apache, or perhaps security arrangements).

Virtual machines, which allow guest operating systems to run on top of a native operating system - such as Windows on Mac OS X, provide a relatively straightforward way of setting up dedicated development environments for each of your customers.

This deck outlines two particular tools which make this incredibly easy.

Chris Aves

October 20, 2015
Tweet

More Decks by Chris Aves

Other Decks in Programming

Transcript

  1. LAMP, MAMP or WAMP Some other 4 letter acronym Web

    Development with Virtual Machines, @ninthspace, 20 October 2015 4
  2. LAMP, MAMP or WAMP Some other 4 letter acronym Homebrew

    Web Development with Virtual Machines, @ninthspace, 20 October 2015 5
  3. LAMP, MAMP or WAMP Some other 4 letter acronym Homebrew

    Whatever your operating system provides by default..? Web Development with Virtual Machines, @ninthspace, 20 October 2015 6
  4. You probably deploy to all sorts of servers? ! !

    ! Web Development with Virtual Machines, @ninthspace, 20 October 2015 10
  5. But.. all your development is in the same environment Web

    Development with Virtual Machines, @ninthspace, 20 October 2015 11
  6. Custom tweaks to get things to work slightly differently for

    a particular client, and let's hope doing that doesn't break that other thing I'm working on Web Development with Virtual Machines, @ninthspace, 20 October 2015 14
  7. Do you work in a team? !"# Web Development with

    Virtual Machines, @ninthspace, 20 October 2015 15
  8. AND EVERYONE has to do something slightly differently Web Development

    with Virtual Machines, @ninthspace, 20 October 2015 17
  9. It's a simulation of a computer, running on your computer

    Web Development with Virtual Machines, @ninthspace, 20 October 2015 29
  10. Any operating system Any environment For free! Web Development with

    Virtual Machines, @ninthspace, 20 October 2015 30
  11. Install other software to mirror your deployment environment Web Development

    with Virtual Machines, @ninthspace, 20 October 2015 35
  12. Then set up the configuration of all that software Web

    Development with Virtual Machines, @ninthspace, 20 October 2015 36
  13. Now you have even more problems! ! Web Development with

    Virtual Machines, @ninthspace, 20 October 2015 38
  14. Wouldn't it be great if you could just automate this?

    Web Development with Virtual Machines, @ninthspace, 20 October 2015 39
  15. Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.hostname = "myubuntu.box" config.vm.network

    :private_network, ip: "192.168.0.42" end Web Development with Virtual Machines, @ninthspace, 20 October 2015 46
  16. But you still have to install all your development software!

    ! Web Development with Virtual Machines, @ninthspace, 20 October 2015 47
  17. Vagrant.configure("2") do |config| config.vm.box = "opscode-ubuntu-12.04_chef-11.4.0" config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.0.box" config.ssh.forward_agent

    = true config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.provision :chef_solo do |chef| chef.cookbooks_path = ["cookbooks"] chef.add_recipe :apt chef.add_recipe 'php' chef.add_recipe 'apache2' chef.add_recipe 'mysql::server' # Loads of configuration stuff goes here for apache and mysql end end Find out about Chef: https://www.chef.io/chef/ Web Development with Virtual Machines, @ninthspace, 20 October 2015 49
  18. ip: "192.168.10.23" memory: 2048 cpus: 1 hostname: suncream name: suncream

    provider: virtualbox authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: "/Users/chris/Work/git/laravel/suncream" to: "/home/vagrant/suncream" type: "nfs" sites: - map: suncream.app to: "/home/vagrant/suncream/public" Web Development with Virtual Machines, @ninthspace, 20 October 2015 57
  19. databases: - homestead variables: - key: APP_ENV value: local ports:

    - send: 2228 to: 22 - send: 8008 to: 80 - send: 44308 to: 443 - send: 33068 to: 3306 - send: 54328 to: 5432 - send: 8028 to: 8025 Web Development with Virtual Machines, @ninthspace, 20 October 2015 58
  20. Other files are located: /etc/php5/cli/php.ini /etc/php5/fpm/php.ini /etc/nginx/nginx.conf PHP Error logs

    are in: /var/log/nginx/<site-name>.log Web Development with Virtual Machines, @ninthspace, 20 October 2015 59
  21. $ composer require laravel/homestead $ php vendor/bin/homestead make $ nano

    Homestead.yaml # just a text editor $ vagrant up Get Composer: https://getcomposer.org Web Development with Virtual Machines, @ninthspace, 20 October 2015 63
  22. What if you're not using PHP? Web Development with Virtual

    Machines, @ninthspace, 20 October 2015 65
  23. $ curl -L http://bit.ly/vaprobash > Vagrantfile $ nano Vagrantfile $

    vagrant up Web Development with Virtual Machines, @ninthspace, 20 October 2015 68
  24. Make sure you know which ports go where. Web Development

    with Virtual Machines, @ninthspace, 20 October 2015 71
  25. Each Virtual Machine needs its own memory, duh. Web Development

    with Virtual Machines, @ninthspace, 20 October 2015 72
  26. $ vagrant package --output some-unique-filename.box Backup your Box. Because a

    backup of a VirtualBox is a Box you can copy it around and use it as a source for a new Virtual Machine. Web Development with Virtual Machines, @ninthspace, 20 October 2015 73
  27. $ rails new Create a new Rails app. Web Development

    with Virtual Machines, @ninthspace, 20 October 2015 77
  28. $ rails new $ otto compile Fetch the dependencies to

    allow the development of that web application. Web Development with Virtual Machines, @ninthspace, 20 October 2015 78
  29. $ rails new $ otto compile $ otto dev Create

    the development environment for the application, then develop! Web Development with Virtual Machines, @ninthspace, 20 October 2015 79
  30. $ rails new $ otto compile $ otto dev $

    otto infra Create the infrastructure on which the application will be deployed. Web Development with Virtual Machines, @ninthspace, 20 October 2015 80
  31. $ rails new $ otto compile $ otto dev $

    otto infra $ otto build Get the web application ready for deployment, e.g. create an EC2 instance and prepare an AMI. Web Development with Virtual Machines, @ninthspace, 20 October 2015 81
  32. $ rails new $ otto compile $ otto dev $

    otto infra $ otto build $ otto deploy Deploys the packaged application into the live infrastructure. Web Development with Virtual Machines, @ninthspace, 20 October 2015 82