Skip to content

Commit 162bba0

Browse files
authored
Update and Fix Vagrant development setup (#1111)
CHANGES - Updated to Ubuntu 20.04 bento vagrant box - Updated PHP to PHP-FPM 7.4 - Updated MySQL to Percona Server 5.7 - Now runs with NGINX as web server (default vhost kept as before http://192.168.50.100/) - DEPRECATED: No longer relying on puphpet code (it's outdated and no longer maintained) - Updated Vagrantfile to use ansible - NEW: Automation in vagrant is now handled by ansible (see provision.yaml for details) - A couple of shell scripts to handle "re-running" of the vagrant up command for faster executions ( setup-php.sh, setup-mysql.sh )
1 parent b81f173 commit 162bba0

File tree

2,155 files changed

+208
-128809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,155 files changed

+208
-128809
lines changed

Diff for: Vagrantfile

+19-262
Original file line numberDiff line numberDiff line change
@@ -1,264 +1,21 @@
1-
require 'yaml'
2-
3-
dir = File.dirname(File.expand_path(__FILE__))
4-
5-
configValues = YAML.load_file("#{dir}/puphpet/config.yaml")
6-
data = configValues['vagrantfile-local']
7-
8-
Vagrant.require_version '>= 1.6.0'
9-
10-
Vagrant.configure('2') do |config|
11-
config.vm.box = "#{data['vm']['box']}"
12-
config.vm.box_url = "#{data['vm']['box_url']}"
13-
14-
if data['vm']['hostname'].to_s.strip.length != 0
15-
config.vm.hostname = "#{data['vm']['hostname']}"
16-
end
17-
18-
if data['vm']['network']['private_network'].to_s != ''
19-
config.vm.network 'private_network', ip: "#{data['vm']['network']['private_network']}"
20-
end
21-
22-
data['vm']['network']['forwarded_port'].each do |i, port|
23-
if port['guest'] != '' && port['host'] != ''
24-
config.vm.network :forwarded_port, guest: port['guest'].to_i, host: port['host'].to_i
25-
end
26-
end
27-
28-
if !data['vm']['post_up_message'].nil?
29-
config.vm.post_up_message = "#{data['vm']['post_up_message']}"
30-
end
31-
32-
if Vagrant.has_plugin?('vagrant-hostmanager')
33-
hosts = Array.new()
34-
35-
if !configValues['apache']['install'].nil? &&
36-
configValues['apache']['install'].to_i == 1 &&
37-
configValues['apache']['vhosts'].is_a?(Hash)
38-
configValues['apache']['vhosts'].each do |i, vhost|
39-
hosts.push(vhost['servername'])
40-
41-
if vhost['serveraliases'].is_a?(Array)
42-
vhost['serveraliases'].each do |vhost_alias|
43-
hosts.push(vhost_alias)
44-
end
45-
end
46-
end
47-
elsif !configValues['nginx']['install'].nil? &&
48-
configValues['nginx']['install'].to_i == 1 &&
49-
configValues['nginx']['vhosts'].is_a?(Hash)
50-
configValues['nginx']['vhosts'].each do |i, vhost|
51-
hosts.push(vhost['server_name'])
52-
53-
if vhost['server_aliases'].is_a?(Array)
54-
vhost['server_aliases'].each do |x, vhost_alias|
55-
hosts.push(vhost_alias)
56-
end
57-
end
58-
end
59-
end
60-
61-
if hosts.any?
62-
if config.vm.hostname.to_s.strip.length == 0
63-
config.vm.hostname = 'puphpet-dev-machine'
64-
end
65-
66-
config.hostmanager.enabled = true
67-
config.hostmanager.manage_host = true
68-
config.hostmanager.ignore_private_ip = false
69-
config.hostmanager.include_offline = false
70-
config.hostmanager.aliases = hosts
71-
end
72-
end
73-
74-
if Vagrant.has_plugin?('vagrant-cachier')
75-
config.cache.scope = :box
76-
end
77-
78-
data['vm']['synced_folder'].each do |i, folder|
79-
if folder['source'] != '' && folder['target'] != ''
80-
sync_owner = !folder['sync_owner'].nil? ? folder['sync_owner'] : 'www-data'
81-
sync_group = !folder['sync_group'].nil? ? folder['sync_group'] : 'www-data'
82-
83-
if folder['sync_type'] == 'nfs'
84-
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'nfs'
85-
elsif folder['sync_type'] == 'smb'
86-
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'smb'
87-
elsif folder['sync_type'] == 'rsync'
88-
rsync_args = !folder['rsync']['args'].nil? ? folder['rsync']['args'] : ['--verbose', '--archive', '-z']
89-
rsync_auto = !folder['rsync']['auto'].nil? ? folder['rsync']['auto'] : true
90-
rsync_exclude = !folder['rsync']['exclude'].nil? ? folder['rsync']['exclude'] : ['.vagrant/']
91-
92-
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
93-
rsync__args: rsync_args, rsync__exclude: rsync_exclude, rsync__auto: rsync_auto, type: 'rsync', group: sync_group, owner: sync_owner
94-
elsif data['vm']['chosen_provider'] == 'parallels'
95-
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
96-
group: sync_group, owner: sync_owner, mount_options: ['share']
97-
else
98-
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
99-
group: sync_group, owner: sync_owner, mount_options: ['dmode=775', 'fmode=764']
100-
end
101-
end
102-
end
103-
104-
config.vm.usable_port_range = (data['vm']['usable_port_range']['start'].to_i..data['vm']['usable_port_range']['stop'].to_i)
105-
106-
if data['vm']['chosen_provider'].empty? || data['vm']['chosen_provider'] == 'virtualbox'
107-
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
108-
109-
config.vm.provider :virtualbox do |virtualbox|
110-
data['vm']['provider']['virtualbox']['modifyvm'].each do |key, value|
111-
if key == 'memory'
112-
next
113-
end
114-
if key == 'cpus'
115-
next
116-
end
117-
118-
if key == 'natdnshostresolver1'
119-
value = value ? 'on' : 'off'
120-
end
121-
122-
virtualbox.customize ['modifyvm', :id, "--#{key}", "#{value}"]
123-
end
124-
125-
virtualbox.customize ['modifyvm', :id, '--memory', "#{data['vm']['memory']}"]
126-
virtualbox.customize ['modifyvm', :id, '--cpus', "#{data['vm']['cpus']}"]
127-
128-
if data['vm']['provider']['virtualbox']['modifyvm']['name'].nil? ||
129-
data['vm']['provider']['virtualbox']['modifyvm']['name'].empty?
130-
if data['vm']['hostname'].to_s.strip.length != 0
131-
virtualbox.customize ['modifyvm', :id, '--name', config.vm.hostname]
132-
end
133-
end
134-
end
135-
end
136-
137-
if data['vm']['chosen_provider'] == 'vmware_fusion' || data['vm']['chosen_provider'] == 'vmware_workstation'
138-
ENV['VAGRANT_DEFAULT_PROVIDER'] = (data['vm']['chosen_provider'] == 'vmware_fusion') ? 'vmware_fusion' : 'vmware_workstation'
139-
140-
config.vm.provider :vmware_fusion do |v, override|
141-
data['vm']['provider']['vmware'].each do |key, value|
142-
if key == 'memsize'
143-
next
144-
end
145-
if key == 'cpus'
146-
next
147-
end
148-
149-
v.vmx["#{key}"] = "#{value}"
150-
end
151-
152-
v.vmx['memsize'] = "#{data['vm']['memory']}"
153-
v.vmx['numvcpus'] = "#{data['vm']['cpus']}"
154-
155-
if data['vm']['provider']['vmware']['displayName'].nil? ||
156-
data['vm']['provider']['vmware']['displayName'].empty?
157-
if data['vm']['hostname'].to_s.strip.length != 0
158-
v.vmx['displayName'] = config.vm.hostname
159-
end
160-
end
161-
end
162-
end
163-
164-
if data['vm']['chosen_provider'] == 'parallels'
165-
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'parallels'
166-
167-
config.vm.provider 'parallels' do |v|
168-
data['vm']['provider']['parallels'].each do |key, value|
169-
if key == 'memsize'
170-
next
171-
end
172-
if key == 'cpus'
173-
next
174-
end
175-
176-
v.customize ['set', :id, "--#{key}", "#{value}"]
177-
end
178-
179-
v.memory = "#{data['vm']['memory']}"
180-
v.cpus = "#{data['vm']['cpus']}"
181-
182-
if data['vm']['provider']['parallels']['name'].nil? ||
183-
data['vm']['provider']['parallels']['name'].empty?
184-
if data['vm']['hostname'].to_s.strip.length != 0
185-
v.name = config.vm.hostname
186-
end
187-
end
188-
end
189-
end
190-
191-
ssh_username = !data['ssh']['username'].nil? ? data['ssh']['username'] : 'vagrant'
192-
193-
config.vm.provision 'shell' do |s|
194-
s.path = 'puphpet/shell/initial-setup.sh'
195-
s.args = '/vagrant/puphpet'
196-
end
197-
config.vm.provision 'shell' do |kg|
198-
kg.path = 'puphpet/shell/ssh-keygen.sh'
199-
kg.args = "#{ssh_username}"
200-
end
201-
config.vm.provision :shell, :path => 'puphpet/shell/install-ruby.sh'
202-
config.vm.provision :shell, :path => 'puphpet/shell/install-puppet.sh'
203-
204-
config.vm.provision :puppet do |puppet|
205-
puppet.facter = {
206-
'ssh_username' => "#{ssh_username}",
207-
'provisioner_type' => ENV['VAGRANT_DEFAULT_PROVIDER'],
208-
'vm_target_key' => 'vagrantfile-local',
209-
}
210-
puppet.manifests_path = "#{data['vm']['provision']['puppet']['manifests_path']}"
211-
puppet.manifest_file = "#{data['vm']['provision']['puppet']['manifest_file']}"
212-
puppet.module_path = "#{data['vm']['provision']['puppet']['module_path']}"
213-
214-
if !data['vm']['provision']['puppet']['options'].empty?
215-
puppet.options = data['vm']['provision']['puppet']['options']
216-
end
217-
end
218-
219-
config.vm.provision :shell do |s|
220-
s.path = 'puphpet/shell/execute-files.sh'
221-
s.args = ['exec-once', 'exec-always']
222-
end
223-
config.vm.provision :shell, run: 'always' do |s|
224-
s.path = 'puphpet/shell/execute-files.sh'
225-
s.args = ['startup-once', 'startup-always']
226-
end
227-
config.vm.provision :shell, :path => 'puphpet/shell/important-notices.sh'
228-
229-
if File.file?("#{dir}/puphpet/files/dot/ssh/id_rsa")
230-
config.ssh.private_key_path = [
231-
"#{dir}/puphpet/files/dot/ssh/id_rsa",
232-
"#{dir}/puphpet/files/dot/ssh/insecure_private_key"
233-
]
234-
end
235-
236-
if !data['ssh']['host'].nil?
237-
config.ssh.host = "#{data['ssh']['host']}"
238-
end
239-
if !data['ssh']['port'].nil?
240-
config.ssh.port = "#{data['ssh']['port']}"
241-
end
242-
if !data['ssh']['username'].nil?
243-
config.ssh.username = "#{data['ssh']['username']}"
244-
end
245-
if !data['ssh']['guest_port'].nil?
246-
config.ssh.guest_port = data['ssh']['guest_port']
247-
end
248-
if !data['ssh']['shell'].nil?
249-
config.ssh.shell = "#{data['ssh']['shell']}"
250-
end
251-
if !data['ssh']['keep_alive'].nil?
252-
config.ssh.keep_alive = data['ssh']['keep_alive']
253-
end
254-
if !data['ssh']['forward_agent'].nil?
255-
config.ssh.forward_agent = data['ssh']['forward_agent']
256-
end
257-
if !data['ssh']['forward_x11'].nil?
258-
config.ssh.forward_x11 = data['ssh']['forward_x11']
259-
end
260-
if !data['vagrant']['host'].nil?
261-
config.vagrant.host = data['vagrant']['host'].gsub(':', '').intern
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
5+
Vagrant.configure("2") do |config|
6+
##### VM definition #####
7+
config.vm.define "phpservermon-dev" do |config|
8+
config.vm.hostname = "phpservermon-dev"
9+
config.vm.box = "bento/ubuntu-20.04"
10+
config.vm.box_check_update = false
11+
config.vm.network "private_network", ip: "192.168.50.100"
12+
config.vm.provision :ansible do |ansible|
13+
ansible.limit = "all"
14+
ansible.playbook = "provision.yaml"
15+
end
16+
config.vm.provider "virtualbox" do |vb|
17+
vb.memory = "2048"
18+
vb.cpus = "2"
26219
end
26320
end
264-
21+
end

Diff for: dev/config.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
define('PSM_DB_PREFIX', 'monitor_');
3+
define('PSM_DB_USER', 'psm');
4+
define('PSM_DB_PASS', 'psm-dev-password');
5+
define('PSM_DB_NAME', 'psm');
6+
define('PSM_DB_HOST', 'localhost');
7+
define('PSM_DB_PORT', '3306'); //3306 is the default port for MySQL. If no specfic port is used, leave it empty.
8+
define('PSM_BASE_URL', '');
9+
define('PSM_WEBCRON_KEY', '');
10+
define('PSM_PUBLIC', false);
11+

Diff for: dev/phpservermon-default

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
upstream php-fpm {
2+
server unix:/var/run/php/php7.4-fpm.sock;
3+
}
4+
5+
server {
6+
listen 80;
7+
server_name 192.168.50.100;
8+
9+
root /vagrant;
10+
index index.php;
11+
charset UTF-8;
12+
13+
gzip on;
14+
gzip_http_version 1.1;
15+
gzip_vary on;
16+
gzip_comp_level 6;
17+
gzip_proxied any;
18+
gzip_types text/plain text/xml text/css application/x-javascript;
19+
20+
access_log /var/log/nginx/psm.access.log;
21+
error_log /var/log/nginx/psm.com.error.log;
22+
23+
location = /favicon.ico {
24+
log_not_found off;
25+
access_log off;
26+
}
27+
28+
location = /robots.txt {
29+
deny all;
30+
log_not_found off;
31+
access_log off;
32+
}
33+
34+
location ~ /\.svn/* {
35+
deny all;
36+
}
37+
38+
location ~ /\.git/* {
39+
deny all;
40+
}
41+
42+
location /nginx_status {
43+
stub_status on;
44+
access_log off;
45+
}
46+
47+
location / {
48+
try_files $uri $uri/ /index.php?q=$uri&$args;
49+
}
50+
51+
location ~ \.php$ {
52+
53+
set $nocache "";
54+
if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) {
55+
set $nocache "Y";
56+
}
57+
58+
fastcgi_pass php-fpm;
59+
fastcgi_index index.php;
60+
fastcgi_param SCRIPT_FILENAME /vagrant$fastcgi_script_name;
61+
fastcgi_intercept_errors on;
62+
include fastcgi_params;
63+
64+
fastcgi_cache_use_stale error timeout invalid_header http_500;
65+
fastcgi_cache_key $host$request_uri;
66+
fastcgi_cache off;
67+
fastcgi_cache_valid 200 1m;
68+
fastcgi_cache_bypass $nocache;
69+
fastcgi_no_cache $nocache;
70+
}
71+
72+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
73+
expires max;
74+
log_not_found off;
75+
}
76+
77+
location ~ ^/(status|ping)$ {
78+
include /etc/nginx/fastcgi_params;
79+
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
80+
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
81+
allow 127.0.0.1;
82+
deny all;
83+
}
84+
}

0 commit comments

Comments
 (0)