├── README.md ├── Vagrantfile ├── config.yaml └── setup.rb /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant PHP 7 Box 2 | A setup and provisioning script for the lightweight [PHP 7 Vagrant box](https://atlas.hashicorp.com/ncaro/boxes/php7-debian8-apache-nginx-mysql/). Run your PHP applications in an extremely performant Vagrant Debian/PHP 7 environment. 3 | 4 | ## Installed with 5 | - Debian 8 (Jessie) 6 | - PHP 7 7 | - PHP 5.6 8 | - PHP-FPM 9 | - MySQL 5.7 10 | - Apache 11 | - Nginx 12 | - Memcached 13 | - Redis 14 | - Node.js 15 | - NPM 16 | - Grunt 17 | - Gulp 18 | - Bower 19 | - Composer 20 | 21 | ## How to use 22 | Map the folders you'd like to sync with Vagrant in the `config.yaml` file. By default, if you place this in the root of your project, it will use that folder. Choose your PHP version and preferred server (defaults to PHP 7 and nginx). 23 | 24 | Run `vagrant up`. That's all. 25 | 26 | ## MySQL 27 | You can access the MySQL instance through SSH, credentials as follows: 28 | 29 | ``` 30 | MySQL Host: 127.0.0.1 31 | Username: root 32 | Password: root 33 | Port: 3306 34 | 35 | SSH IP: {your-ip} 36 | SSH User: vagrant 37 | SSH Password: vagrant 38 | SSH Key: ~/.vagrant.d/insecure_private_key (this may be different depending on your environment) 39 | SSH Port: 2222 40 | ``` 41 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | require 'json' 5 | require 'yaml' 6 | 7 | configFile = File.expand_path("./config.yaml") 8 | require_relative 'setup.rb' 9 | 10 | Vagrant.configure(2) do |config| 11 | 12 | Build.configure(config, YAML::load(File.read(configFile))) 13 | 14 | end 15 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | ip: "192.168.7.7" 3 | memory: 1024 4 | cpus: 2 5 | 6 | networking: 7 | - public: true 8 | 9 | folders: 10 | - map: . 11 | to: /var/www/html 12 | type: nfs 13 | 14 | # PHP options: 5 (uses 5.6) or 7 15 | php: 7 16 | 17 | # Uses nginx + PHP-FPM. If set to false, uses Apache. 18 | nginx: true 19 | 20 | # ports: 21 | # - guest: 80 22 | # host: 8000 23 | 24 | 25 | -------------------------------------------------------------------------------- /setup.rb: -------------------------------------------------------------------------------- 1 | class Build 2 | def Build.configure(config, settings) 3 | 4 | # Configure The Box 5 | config.vm.box = "ncaro/php7-debian8-apache-nginx-mysql" 6 | 7 | # Configure A Private Network IP 8 | config.vm.network :private_network, ip: settings["ip"] ||= "192.168.7.7" 9 | 10 | if settings['networking'][0]['public'] 11 | config.vm.network "public_network", type: "dhcp" 12 | end 13 | 14 | # Configure A Few VirtualBox Settings 15 | config.vm.provider "virtualbox" do |vb| 16 | vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"] 17 | vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"] 18 | vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] 19 | vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] 20 | vb.customize ["modifyvm", :id, "--ostype", "Debian_64"] 21 | vb.customize ["modifyvm", :id, "--audio", "none", "--usb", "off", "--usbehci", "off"] 22 | end 23 | 24 | # Configure Port Forwarding To The Box 25 | config.vm.network "forwarded_port", guest: 80, host: 8000 26 | config.vm.network "forwarded_port", guest: 443, host: 44300 27 | config.vm.network "forwarded_port", guest: 3306, host: 33060 28 | 29 | # Add Custom Ports From Configuration 30 | if settings.has_key?("ports") 31 | settings["ports"].each do |port| 32 | config.vm.network "forwarded_port", guest: port["guest"], host: port["host"], protocol: port["protocol"] ||= "tcp" 33 | end 34 | end 35 | 36 | # Register All Of The Configured Shared Folders 37 | if settings['folders'].kind_of?(Array) 38 | settings["folders"].each do |folder| 39 | config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil 40 | end 41 | end 42 | 43 | # Turn on PHP-FPM for nginx, or enable the right module for Apache 44 | if settings["php"] == 7 45 | if settings["nginx"] ||= false 46 | config.vm.provision "shell", inline: "sudo service php5-fpm stop && sudo service php7-fpm restart" 47 | else 48 | config.vm.provision "shell", inline: "sudo a2dismod php5 && sudo a2enmod php7" 49 | end 50 | else 51 | if settings["nginx"] ||= false 52 | config.vm.provision "shell", inline: "sudo service php7-fpm stop && sudo service php5-fpm restart" 53 | else 54 | config.vm.provision "shell", inline: "sudo a2dismod php7 && sudo a2enmod php5" 55 | end 56 | end 57 | 58 | # Turn on the proper server 59 | config.vm.provision "shell" do |s| 60 | if settings["nginx"] ||= false 61 | s.inline = "sudo apachectl stop && sudo service nginx restart" 62 | else 63 | s.inline = "sudo service nginx stop && sudo apachectl restart" 64 | end 65 | end 66 | 67 | end 68 | end 69 | --------------------------------------------------------------------------------