- Virtual Box https://www.virtualbox.org/wiki/Downloads
- Vagrant https://www.vagrantup.com/downloads.html
Boxes https://atlas.hashicorp.com/boxes/search
Settings https://docs.vagrantup.com/v2/vagrantfile/machine_settings.html
Forward Ports
config.vm.network "forwarded_port", guest: 8888, host: 8990
Provision
config.vm.provision "chef_solo" do |chef|
chef.install = true
chef.add_recipe "basic"
end
cd into your project structure and run:
mkdir -p cookbooks/basic/recipes
mkdir -p cookbooks/basic/files/default
touch cookbooks/basic/recipes/default.rb
Open the default.rb file in a code editor
default.rb
#
# Cookbook Name:: basic
# Recipe:: default
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
execute "apt-get-update" do
command "apt-get update"
ignore_failure true
action :run
end
package 'apache2'
execute "apache-remove-www" do
command "rm -rf /var/www"
end
execute "apache-link-www" do
command "ln -fs /vagrant/ /var/www"
end
execute "apache-enable-rewrite" do
command "a2enmod rewrite"
end
execute "apache-override-all" do
command "sed -i '/AllowOverride None/c AllowOverride All' /etc/apache2/sites-available/*"
end
In the root of your project
vagrant init
Open Vagrantfile file in a code editor
Vagrantfile
config.vm.box = "hashicorp/precise32"
config.vm.network "forwarded_port", guest: 8888, host: 8990
config.vm.provision "chef_solo" do |chef|
chef.install = true
chef.add_recipe "basic"
end
More:
npm init
npm install express --save
touch app.js
- Copy hello world example into app.js http://expressjs.com/starter/hello-world.html
- Add
package nodejs
to default.rb - add to default.rb:
execute "update-node-package" do
command "curl -sL https://deb.nodesource.com/setup | sudo bash -"
end
package 'nodejs'
execute "install-nodemon" do
command "npm install -g nodemon"
end
execute "update-npm" do
command "cd /vagrant/ && npm install"
end
execute "start-node-server" do
command "nodemon /vagrant/app.js"
end
Update Packages
# update package list
execute "apt-get-update" do
command "apt-get update"
ignore_failure true
action :run
end
Install Packages
package 'apache2'
Apache Stuff
execute "apache-remove-www" do
command "rm -rf /var/www"
end
execute "apache-link-www" do
command "ln -fs /vagrant/ /var/www"
end
execute "apache-enable-rewrite" do
command "a2enmod rewrite"
end
execute "apache-override-all" do
command "sed -i '/AllowOverride None/c AllowOverride All' /etc/apache2/sites-available/*"
end
Include Files
cookbook_file "/usr/share/nginx/www/index.html" do
source "index.html" #found in cookbooks/basic/files/default
mode "0644"
end