├── Vagrantfile ├── cookbooks └── main │ ├── templates │ └── default │ │ └── vhost.erb │ └── recipes │ └── default.rb └── index.php /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | 3 | config.vm.box = "ubuntu/trusty64" 4 | #config.vm.box_url = "myawesomeurl.foogle" 5 | 6 | config.vm.network :private_network, ip: "192.168.33.101" 7 | #config.vm.network "forwarded_port", guest: 80, host: 8080 8 | 9 | config.vm.provider "virtualbox" do |vb| 10 | vb.memory = 1024 11 | vb.cpus = 2 12 | end 13 | 14 | config.vm.provision "chef_solo" do |chef| 15 | chef.add_recipe "main" 16 | end 17 | 18 | config.vm.synced_folder ".", "/var/www" 19 | 20 | end -------------------------------------------------------------------------------- /cookbooks/main/templates/default/vhost.erb: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | root <%= @doc_root %>; 5 | index index.html index.php; 6 | 7 | server_name <%= @server_name %>; 8 | 9 | location / { 10 | try_files $uri $uri/ /index.php; 11 | } 12 | 13 | error_page 404 /404.html; 14 | 15 | error_page 500 502 503 504 /50x.html; 16 | location = /50x.html { 17 | root /usr/share/nginx/www; 18 | } 19 | 20 | location ~ \.php$ { 21 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 22 | fastcgi_pass unix:/var/run/php5-fpm.sock; 23 | fastcgi_index index.php; 24 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 25 | include fastcgi_params; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 36 | 37 | 38 |
39 |
40 |
Welcome Neo...
41 |
to the virtual world
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /cookbooks/main/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # start of by updating your repos 2 | 3 | execute "apt-get update" do 4 | command "apt-get update" 5 | end 6 | 7 | 8 | # let's install some packages... 9 | 10 | # get the basics 11 | 12 | base-packages = ['curl', 'unzip', 'git', 'build-essential'] 13 | 14 | base-packages.each do |pckg| 15 | apt_package pckg do 16 | action :install 17 | end 18 | end 19 | 20 | # get all the php related stuff 21 | 22 | php-packages = ["php5-fpm", 'php5-curl','php5-cli'] 23 | 24 | php-packages.each do |pckg| 25 | apt_package pckg do 26 | action :install 27 | end 28 | end 29 | 30 | # and a web server 31 | 32 | apt_package "nginx" do 33 | action :install 34 | end 35 | 36 | # some databases 37 | 38 | databases = ['mysql-server', 'redis-server', 'beanstalkd'] 39 | 40 | databases.each do |db| 41 | apt_package db do 42 | action :install 43 | end 44 | end 45 | 46 | 47 | # now we need to start up some services if we want our server to actually do things 48 | 49 | services = ['nginx', 'php5-fpm', 'mysql', 'redis-server', 'beanstalkd'] 50 | 51 | services.each do |srvc| 52 | service srvc do 53 | action [ :enable, :start ] 54 | end 55 | end 56 | 57 | # almost done... 58 | 59 | # set up a virtual host for our awesome site 60 | 61 | template "/etc/nginx/sites-available/default" do 62 | source "vhost.erb" 63 | variables({ 64 | :doc_root => "/var/www", 65 | :server_name => "192.168.33.101" 66 | }) 67 | action :create 68 | notifies :restart, resources(:service => "nginx") 69 | end 70 | 71 | # dance 72 | --------------------------------------------------------------------------------