Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit a6f6b2a

Browse files
committed
Changed to a HOSTNAME file and updated Vagrantfile comments to reflect current status of executable lines.
1 parent d68bd7a commit a6f6b2a

File tree

3 files changed

+131
-37
lines changed

3 files changed

+131
-37
lines changed

HOSTNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wplib.box

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,18 @@ After this you should have a running WPLib Box via Vagrant and VirtualBox and a
134134
<a id="setting-domain"></a>
135135
##Setting the Domain Name
136136

137-
To use WPLib Box for a local domain name other than `wplib.box` edit the `Vagrantfile` and replace the text `"wplib.box"` with your preferred local domain name _(we recommend `"your-production-domain.dev"`):_
137+
To use WPLib Box for a local domain name other than `wplib.box` edit the `HOSTNAME` file _(with no extension)_
138+
and replace the text `"wplib.box"` with your preferred local domain name _(we recommend `"your-production-2nd-level-domain.dev"` e.g. if `google.com` then use `google.dev`):_
138139

139-
In other words, change this:
140+
In other words, change the **entire contents** of the `HOSTNAME` file from this:
140141

141-
config.vm.hostname = "wplib.box"
142+
wplib.box
142143

143144
To _(something like)_ this:
144145

145-
config.vm.hostname = "example.dev"
146+
example.dev
146147

147-
Save the changes to `Vagantfile` and then run the following commands to reload the Vagrant configuration, and then open in your browser. _(Be sure you replaced the domain name in the 2nd command with your own local domain name):_
148+
Save the changes to `HOSTNAME` and then run the following commands to reload the Vagrant configuration, and then open in your browser. _(Be sure you replaced the domain name in the 2nd command with your own local domain name):_
148149

149150
vagrant reload
150151
open "http://example.dev"
@@ -154,7 +155,7 @@ Save the changes to `Vagantfile` and then run the following commands to reload t
154155

155156
The default local IP address used by this box is `10.10.10.{octet}` where `{octet}` is a number between 10 to 250.
156157

157-
If you need to change that for any reason simply edit the file named just `IP` _(with no extension)_ found in the project root. It is created during `vagrant up` and a random `{octet}` is generated. Just edit this file and change the IP address it contains.
158+
If you need to change that for any reason simply **edit the file named just `IP`** _(with no extension)_ found in the project root. It is created during `vagrant up` and a random `{octet}` is generated. Just edit this file and change the IP address it contains.
158159

159160

160161
<a id="web-php"></a>

Vagrantfile

Lines changed: 123 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@
5454
#
5555
# REFERENCE:
5656
#
57+
# config.vm.box = "wplib/wplib"
58+
#
59+
# This line specifies the VM "box" image which is hosted for
60+
# download on Hashicorp's Atlas Vagrant Box Repository here:
61+
#
62+
# https://atlas.hashicorp.com/wplib/boxes/wplib
63+
#
64+
# This box image is a pre-provisioned Ubuntu Linux 14.04 LTS
65+
# with nginx, MySQL, PHP7.0/5.6 and more; everything a good
66+
# a Linux server needs to be able to serve WordPress pages.
67+
#
68+
# In many ways -- compared to Vagrant boxes like VVV and VIP
69+
# Quickstart -- this is WPLib's "secret sauce."
70+
#
5771
# File.write('IP', "10.10.10.#{rand(10..250)}") if not File.exists?('IP')
5872
#
5973
# This line creates a randomly-generated and non-routable IP
@@ -79,35 +93,87 @@
7993
# If we can find a better approach later, we will be happy
8094
# to switch to it.
8195
#
82-
# config.vm.box = "wplib/wplib"
96+
# File.write('HOSTNAME', "wplib.box") if not File.exists?('HOSTNAME')
8397
#
84-
# This line specifies the VM "box" image which is hosted for
85-
# download on Hashicorp's Atlas Vagrant Box Repository here:
98+
# This line writes the host name of 'wplib.box' to a file
99+
# named 'HOSTNAME' in the project's root folder, the same
100+
# folder in which this Vagrantfile is found to ensure future
101+
# runs of "vagrant up" or "vagrant reload" use the same host
102+
# name, unless of course you change it, which we expect.
86103
#
87-
# https://atlas.hashicorp.com/wplib/boxes/wplib
104+
# The host name in this context is a domain name local to
105+
# your computer which you can access via your browser by
106+
# prefixing the host name with 'http://', for example
107+
# http://wplib.box or http://example.dev.
88108
#
89-
# This box image is a pre-provisioned Ubuntu Linux 14.04 LTS
90-
# with nginx, MySQL, PHP5.6 and more; essentially everything
91-
# a Linux server needs to be able to serve WordPress pages.
109+
# To change the host name of your WPLib Box simple update
110+
# the `HOSTNAME` file to include only your preferred host
111+
# name, e.g. `example.dev` or similar (but without the
112+
# quotes).
92113
#
93-
# In many ways -- compared to Vagrant boxes like VVV and VIP
94-
# Quickstart -- this is WPLib's "secret sauce."
114+
# hostname = IO.read('HOSTNAME').strip;
115+
#
116+
# This line reads the value in the file named 'HOSTNAME',
117+
# strips off any leading or trailing whitespace and then
118+
# assignes it to a variable named 'hostname' which is
119+
# local to this Vagrantfile.
95120
#
96-
# config.vm.hostname = "wplib.box"
121+
# If the previous line wrote the file then it will load
122+
# 'wplib.box' otherwise it will load a host name that
123+
# you have updated the 'HOSTNAME' file to include, such
124+
# as 'example.dev' or similar (but without the quotes).
125+
#
126+
# config.vm.hostname = hostname
97127
#
98128
# This line specifies the domain name your browser should be
99129
# able to load the WordPress site running inside this box.
100130
#
131+
# This value comes from the file named 'HOSTNAME' which was
132+
# created and/or read into the variable 'hostname' in the
133+
# previous two lines.
134+
#
101135
# To CHANGE the domain name to use to when loading the box's
102-
# website in your browser you only need to change this line;
103-
# change "wplib.box" to your preferred local domain name and
104-
# then run "vagrant reload" in your terminal.
136+
# website in your browser you only need to update the file
137+
# named 'HOSTNAME', or create one if it does not already
138+
# exist. It should be a text file than only contains the
139+
# local domain name that you want to use to access the
140+
# website(s) on your WPLib Box.
105141
#
106142
# Of course your computer's hosts file must contain the IP
107143
# address used by the box for your browser to use it to load
108144
# WordPress but if you have the Vagrant hosts-updater plugin
109145
# then it will handle updating the hosts file for you.
110146
#
147+
# Assuming you have that plugin, once you've updated the
148+
# 'HOSTNAME' file run "vagrant up" or "vagrant reload" in
149+
# your terminal to update your computer's 'hosts' file to
150+
# recognize this domain name when typed into your browser.
151+
#
152+
# config.hostsupdater.aliases = [
153+
# "www.#{hostname}",
154+
# "adminer.#{hostname}",
155+
# "mailhog.#{hostname}"
156+
# ]
157+
#
158+
# These lines specify addition domains that WPLib Box will
159+
# add to your hosts file (assuming you have the Vagrant
160+
# hosts-updater plugin) and thus WPLib Box will be able to
161+
# recognize when you request them from your browser.
162+
#
163+
# You'll note the use the same (base) host name as the
164+
# prior line so look to its description for further details
165+
# on the 'hostname' variable.
166+
#
167+
# These lines add a 'www.' alias, domains for Adminer (which
168+
# is like phpMyAdmin, only better) and for Mailhog (that
169+
# captures outgoing email into a web email interface, great
170+
# for accessing the password change request emails that are
171+
# normally so hard to track down during development,
172+
# especially if sent to someone else's email address!)
173+
#
174+
# You can add other domains here that you might need, such
175+
# as subdomains of your domain, if you have that need.
176+
#
111177
# config.vm.network 'private_network', ip: IO.read('IP').strip
112178
#
113179
# This line tells Vagrant what IP address to use for the VM.
@@ -191,11 +257,31 @@
191257
# - https://github.com/mitchellh/vagrant/tree/master/keys
192258
# - https://twitter.com/mitchellh/status/525704721714012160
193259
#
194-
# config.vm.provision "shell", path: "scripts/provision.sh"
260+
# $provision = <<PROVISION
261+
# if [ -f "/vagrant/scripts/provision.sh" ]; then
262+
# bash /vagrant/scripts/provision.sh --force
263+
# else
264+
# rm -rf /tmp/box-scripts 2>/dev/null
265+
# git clone https://github.com/wplib/box-scripts.git /tmp/box-scripts 2>/dev/null
266+
# bash /tmp/box-scripts/provision.sh
267+
# fi
268+
# PROVISION
269+
#
270+
# These lines create an "inline" provisioning script to be
271+
# run on the FIRST "vagrant up" or on any "vagrant up" or
272+
# "vagrant reload" that has the "--provision" switch.
273+
#
274+
# This inline script checks for a provision script on disk
275+
# named '/vagrant/scripts/provision.sh' and if there it
276+
# runs it. If not there it pulls it down from GitHub by
277+
# cloning the script, and then it runs it.
278+
#
279+
# config.vm.provision "shell", inline: $provision
195280
#
196-
# This line tells Vagrant to run the bash script named
197-
# "provision.sh" found in the "scripts" folder which is in
198-
# the same folder where Vagrantfile is located.
281+
# This line tells Vagrant to run the "inline" bash script
282+
# described above, which ultimately runs the "provision.sh"
283+
# found in the "scripts" folder which is in the same folder
284+
# where Vagrantfile is located.
199285
#
200286
# This provision script runs a few quick commands, such as
201287
# importing "/sql/default.sql" which is the default MySQL
@@ -209,16 +295,17 @@
209295
#
210296
# REUSE:
211297
#
212-
# When you cloning the WPLib Box repository you are getting an
298+
# When you clone the WPLib Box repository you are getting an
213299
# "appliance" for WordPress local development that is designed
214-
# to "just work" if at all possible.
300+
# to "just work," if at all possible.
215301
#
216-
# However once comfortable with WPLib Box few developers will
217-
# want to start a problem by first using "git clone" on the
218-
# github.com/wplib/wplib-box repository. In point of fact, we
219-
# don't even use WPLib Box in that manner.
302+
# However once comfortable with WPLib Box most developers will
303+
# probably not want to start with a "git clone" of the
304+
# github.com/wplib/wplib-box repository but instead maintain
305+
# their own Vagrantfile which is based off this one. In point
306+
# of fact, this is how we use WPLib Box ourselves.
220307
#
221-
# Instead developers will want a recipe for how to use WPLib
308+
# But we believe developers want a recipe for how to use WPLib
222309
# Box in their projects with the least effort required. And
223310
# that is exactly how WPLib Box is intended to be used once
224311
# a developer becomes familiar with it.
@@ -228,9 +315,9 @@
228315
#
229316
# 1. Copy this file into a new Vagrantfile in your project.
230317
#
231-
# 2. Change config.vm.hostname = "wplib.box" to replace the
232-
# value of "wplib.box" with the local development domain
233-
# of your project, e.g. "dev.example.com"
318+
# 2. Create a/update the HOSTNAME file and replace 'wplib.box'
319+
# with a local domain name relevant to your project, for
320+
# examples: 'acme.dev' or 'example.dev'.
234321
#
235322
# 3. Either delete the link with config.vm.provision "shell"
236323
# or copy "scripts/provision.sh" and modify it to run
@@ -252,13 +339,18 @@
252339

253340
Vagrant.configure(2) do |config|
254341

342+
config.vm.box = "wplib/wplib"
343+
255344
File.write('IP', "10.10.10.#{rand(10..250)}") if not File.exists?('IP')
345+
File.write('HOSTNAME', "wplib.box") if not File.exists?('HOSTNAME')
256346

257-
config.vm.box = "wplib/wplib"
258-
config.vm.hostname = "wplib.box"
347+
hostname = IO.read('HOSTNAME').strip;
348+
349+
config.vm.hostname = hostname
259350
config.hostsupdater.aliases = [
260-
"adminer.wplib.box",
261-
"mailhog.wplib.box"
351+
"www.#{hostname}",
352+
"adminer.#{hostname}",
353+
"mailhog.#{hostname}"
262354
]
263355

264356
config.vm.network 'private_network', ip: IO.read('IP').strip

0 commit comments

Comments
 (0)