4 <meta content="text/html; charset=windows-1252" http-equiv="content-type">
5 <title>Cake LAMP VM Documentation</title>
8 <h1 style="text-align: center;">The cakelampvm VM:<br>
9 Configuration and Usage</h1>
10 <h2 style=" text-align: center;">By Chris Koeritz</h2>
11 <h3 style=" text-align: center;"> Vintage: cakelampvm v002
12 Updated: 2017-11-16</h3>
13 <p>The cakelampvm project provides a virtualbox VM that acts as an "internet
14 in a bottle". The virtual machine provides DNS services (<a title="dns server"
15 href="http://www.bind9.net/">bind9</a>), a Web server (<a title="patchy"
16 href="https://httpd.apache.org/">Apache2</a>), a full <a title="ubuntu means compassion and humanity"
17 href="https://www.ubuntu.com/">Ubuntu</a> <a title="it's pronounced leenoox"
18 href="https://www.linuxfoundation.org/">Linux</a> desktop environment,
19 the <a title="flux is change" href="http://fluxbox.org/">Fluxbox</a> <a
20 title="a better windows" href="https://www.x.org/">X window manager</a>,
21 and a suite of tools called the <a title="feisty meow® concerns ltd. website"
22 href="https://feistymeow.org/">Feisty Meow® codebase</a> .
23 Together, these services provide you with a very flexible and powerful
24 testbed for web development, especially suited for <a title="it's cake" href="https://cakephp.org/">CakePHP</a>.</p>
25 <p>todo: arrange gritty details to back.</p>
26 <p>todo: toc goes here.</p>
28 <h2><span style="text-decoration: underline;">G</span>uest VM Configuration</h2>
30 <li>hostname: <a title="the vm's website, when configured properly" href="https://cakelampvm.com/">cakelampvm.com</a></li>
31 <li>local IP address: 10.28.42.20</li>
32 <li>services: DNS (bind9), apache2, fluxbox X windowing system, <a title="not just in the garden"
33 href="https://www.gnome.org/">gnome display manager</a></li>
34 <li>main user: developer (password distributed separately)</li>
35 <li>mysql root password: (password distributed separately)</li>
37 <h2>Powering up with the Feisty Meow® scripts</h2>
38 <p>[First, let me drop the registered trademark symbol from here on
39 in. I hope its presence above has been sufficiently clear for legal
40 purposes, but now it will just get in the way. Also, capitalization
41 really bores me, and it's the feisty meow codebase anyhow, so that's how
42 it will be written henceforth.]</p>
43 <p>The feisty meow scripts are a cohesive bash scripting environment for
44 getting a variety of tasks done. The scripts recently incorporated
45 the 'avbash' collection from Saco Designs and added those scripts to the
46 "site_avenger" collection of scripts. These provide tools for
47 bringing up CakePHP web sites and managing the collection of repositories
48 for those sites. Each website is considered an "application", and
49 the application name itself (e.g. "winterportlibrary") can often provide
50 all the details for "powering up" the site. The feisty meow team has
51 added additional scripts for managing DNS domains and Apache websites that
52 provide the capability to "stand up" an entire website around an
53 application, with accompanying domain.</p>
54 <p>The site avenger scripts are documented separately within the feisty meow
55 codebase. Consult the <span style="text-decoration: underline;">f</span><a
56 title="quickstart" href="https://feistymeow.org/feisty_meow/readme.txt">eisty
58 readme</a> file first, as it provides some valuable information on
59 configuring the codebase. The site avenger script documentation is
60 available in the <a title="useful commands" href="https://feistymeow.org/feisty_meow/documentation/feisty_meow_command_reference.txt">feisty
61 meow command reference</a> file.</p>
62 <p>(The feisty meow codebase is already configured for the developer account
63 on the cakelampvm virtual machine.)</p>
64 <h2>How to set up virtualbox for your host PC</h2>
66 <li>Download and install virtualbox:
67 https://www.virtualbox.org/wiki/Downloads</li>
68 <li>Install the extension pack for virtualbox: This provides USB drivers
69 and other features. This is installed on virtualbox itself, not on
72 <li>Download the extension pack at
73 https://www.virtualbox.org/wiki/Downloads</li>
74 <li>Stop any running virtualbox vms.</li>
75 <li>Close virtualbox control panel.</li>
76 <li>Double-click on the downloaded extensions package (in a file
77 explorer) and virtualbox should install it.</li>
79 <li>Run the virtualbox control panel.</li>
80 <li>Download the cakelampvm guest vm package and unzip it. Store the
81 unzipped version in some appropriate place where you want the virtual
82 machine to reside on your host's hard drive.</li>
83 <li>Add the guest VM to your list of VMs. From the virtualbox menus,
84 choose the "Machine" menu and select "Add". Point the selector
85 dialog at the cakelampvm folder you created above and open the
86 cakelampvm.vbox file.</li>
87 <li>Now the cakelampvm should show up in the list of virtual
88 machines. Before starting it, perform the following network
89 configuration sections.</li>
91 <h3>Configure the Host-Only network on virtualbox</h3>
92 <p>Configuring host-only networking for the VM makes the VM completely local
93 to your machine. The cakelampvm will not be accessible on the
94 internet or from the LAN, and can only be accessed by your host PC.</p>
96 <li> Go to virtual box "Preferences" (global preferences, not for a
98 <li> Click on the "Network" tab.</li>
99 <li> Choose the "Host-only Networks" tab from within "Network".</li>
100 <li> Click the plus icon to add a new host-only network, or if there is
101 already a Host-only network, then edit it.</li>
102 <li>Set the "Adapter" parameters:<br>
103 IPv4 Address: 10.28.42.1<br>
104 IPv4 Network Mask: 255.255.255.0<br>
105 IPv6 Address: (leave blank)<br>
106 IPv6 Prefix Length: 0<br>
107 Virtualbox will fill in the other details like so:<br>
108 <p><img alt="host only network adapter" src="images/host_only_network_adapter.png"></p>
110 <li>Set the "DHCP Server Settings" to disabled, e.g.<br>
111 <img alt="host only dhcp" src="images/host_only_adapter_dhcp_server.png"><br>
112 This is disabled because we will be using statically assigned addresses
113 for convenience and stability.</li>
115 <p>Additional information on host-only (and other) network adapter types is
116 at: https://www.virtualbox.org/manual/ch06.html#network_nat_service<br>
118 <h3>Configure the Nat Network on virtualbox</h3>
120 <li> Go to virtual box "Preferences" (global preferences, not for a
122 <li> Click on the "Network" tab.</li>
123 <li> Choose the "Nat Networks" tab from within "Network".</li>
124 <li> Click the plus icon to add a new host-only network.</li>
125 <li>Set the "NAT Network Details" parameters:<br>
126 Network Name: NatNetwork<br>
127 Network CIDR: 10.0.2.0/24<br>
128 Supports DHCP: checked<br>
129 Supports IPv6: optionally checked<br>
130 These are my settings, with IPv6 left disabled:<br>
131 <img alt="nat net config" src="images/nat_network_config.png"></li>
133 <h2>Start up the VM</h2>
134 <p>Using the virtualbox interface, you should now be able to start your
135 virtual machine. Virtualbox will complain if it detects any
136 remaining configuration problems in the VM, but it should start
137 normally. The Linux boot sequence will show many lines of text,
138 before bringing up a black console window with a login dialog.</p>
139 <p>You can log in directly on the VM console with the developer account, but
140 it is generally more useful to connect to the cakelampvm over ssh.
141 If the networking has been established properly, you should be able to do
143 <pre>ssh developer@cakelampvm.com (or equivalent with your ssh client)</pre>
144 <p>And then provide the password to log in.</p>
145 <p>A feature called "X forwarding" is enabled, so if you start graphical
146 applications on the VM, you can display them from an appropriately
147 configured host. (If you're running Linux as the host for the VM,
148 you can definitely run remote windows. Windows may not support
150 <p>#### check this!!!</p>
151 <h2>Using the guest VM's DNS services</h2>
152 <p>The cakelampvm has been set up to provide a DNS server which will answer
153 name requests for all of the sites that the VM hosts.</p>
154 <p>To use the cakelampvm DNS, modify your host operating system network
155 configuration by adding or changing the DNS server to use the guest VM's
156 DNS service. This is available at the local address
157 10.28.42.20. The DNS server can be tested with nslookup, dig and
159 <p>Note that the cakelampvm DNS should be listed first, if one intends to
160 override any DNS names that actually exist out on the internet.</p>
161 <p>If the DNS server is properly set up, then these ping commands should get
162 answering responses:</p>
163 <pre>ping cakelampvm.com</pre>
164 <pre>ping defaultcake.cakelampvm.com</pre>
165 <pre>ping mapsdemo.cakelampvm.com</pre>
166 <h3>Setting up DNS on Windows</h3>
167 <p>The ipconfig tool will provide helpful information about your current
168 networking and DNS configuration:</p>
169 <pre>ipconfig --all</pre>
170 <p>The DNS configuration on Windows is somewhat byzantine. The pipe
171 characters ('|') below are used to separate the menus or tabs or dialogs
172 to traverse. Follow this path to get to the DNS config:</p>
173 <pre>Control Panel | Network & Sharing | click WiFI or Ethernet link near top right | click Adapter Settings on left | click on specific network device to modify | select Properties</pre>
180 <h2>Editing files on the guest VM from the host</h2>
181 <p>On the host computer, look for the guest vm as a networked computer
182 called cakelampvm. This should provide some network shares using
183 Microsoft SMB protocol, and they can be attached to using the "developer"
184 user and its password.</p>
185 <p>On windows, one may want to mount this network location as a drive letter
186 for easier access.</p>
187 <p>Currently, the root of all web servers is exposed as "www". Editing
188 the files in those folders requires ownership by the developer user.
189 Currently the defaultcake server is owned by developer.</p>
190 <p>One should be able to create a new directory in the www folder owned by
191 the developer user over the network also, which can be used for creating
192 new projects. However, there is a config issue in the current vm
193 (v001) about this; to fix, run this command on the guest vm as the
195 <pre>sudo chmod g+w /var/www</pre>
196 <p>Afterwards, the www folder should allow the developer user to create new
198 <h2>Accessing files on the host PC from the guest VM</h2>
199 <p>If you want to share a folder from the host to the guest, perhaps for
200 driver updates or other conveniences, then make the share with these
203 <li>Create a folder on the host that is to be shared.</li>
204 <li>Right-click on the vm in virtualbox manager and choose "Settings".</li>
205 <li>In the "Shared Folders" tab of the settings, go to "Machine Folders".</li>
206 <li>Click the folder plus icon to create a new share.</li>
207 <li>Fill in the "Folder Path" on the host PC to the folder that will be
208 shared, and give it a name for the guest. We assume the folder
209 name will be "myshare".</li>
210 <li>On the guest vm, run the following commands to mount the share:<br>
211 <pre>mkdir ~/shared # for the guest's version of the shared folder</pre>
212 <pre>sudo mount -t vboxsf myshare ~/shared # mount the vm's share name onto the folder on the vm.</pre>
215 <h2>Adding a new website and domain on the guest VM</h2>
216 <p>To add a new website, you will need to pick one of the DNS options below
217 (A or B) depending on how you want to name the site. After the DNS
218 is updated, then follow the section after for creating a new apache conf
220 <p>Assuming one has created a new folder in "www" called "greatsite", then
221 the new web site can be brought online on the vm with one of the following
223 <h3>DNS Option A: Using a sub-domain in the cakelampvm.com domain</h3>
224 Connect to the cakelampvm via ssh as the developer user, e.g.: ssh
225 developer@cakelampvm.com
226 <p>Execute the following command to edit the DNS file for the cakelampvm
228 <pre>sudo vi /etc/bind/cakelampvm.com.conf</pre>
229 <p>Add a stanza for the new site at the end of this file:</p>
230 <pre>greatsite.cakelampvm.com IN A 10.28.42.20<br> IN HINFO "linux server" "ubuntu"</pre>
231 <p>Restart the DNS server: sudo service bind9 restart</p>
232 <p>Afterwards, pinging greatsite.cakelampvm.com should work from either the
233 guest or the host.</p>
234 <h3>DNS Option B: Using an entirely new domain for the site</h3>
235 <p>Similar procedure to above, but we will create a new file for the new
236 domain and add it to the bind directory. For this example, we will
237 create a file called /etc/bind/greatsite.tv.conf for our new domain
238 greatsite.tv with these contents:</p>
239 <pre>$TTL 1W<br>@ IN SOA @ fred.cakelampvm.com. (<br> 2017100801 ; serial<br> 2H ; refresh<br> 8M ; retry<br> 14D ; expiry<br> 6H ) ; minimum<br><br> IN NS ns.cakelampvm.com.<br> IN MX 10 mail.cakelampvm.com.<br><br># main domain for machine.<br>greatsite.tv. IN A 10.28.42.20<br> IN HINFO "linux server" "ubuntu"</pre>
240 The gnarly prefix stuff above the "greatsite.tv." listing establishes
241 configuration info for the new domain. This file relies on the
242 existing cakelampvm.com infrastructure in DNS, such as the "ns" host, which
243 is the domain's name server.
244 <p>Now that the config file is in place, edit "named.conf.local" to add the
245 new file by adding this bit of configuration at the end:</p>
246 <pre>zone "greatsite.tv" in {<br> file "/etc/bind/greatsite.tv.conf";<br> type master;<br> allow-query { any; };<br>};</pre>
247 <p>Restart the DNS server: sudo service bind9 restart</p>
248 <p>Afterwards, pinging greatsite.tv should work from either the guest or the
250 <h3>Create a new apache configuration file and load it</h3>
251 <p>Start with the following template file for the new website, and modify it
252 for the appropriate host name:</p>
253 <pre><VirtualHost *:80><br> ServerName greatsite.cakelampvm.com<br> ServerAlias greatsite.cakelampvm.com *.greatsite.cakelampvm.com<br> DocumentRoot /var/www/greatsite<br> ErrorLog ${APACHE_LOG_DIR}/greatsite.cakelampvm.com-error.log<br> CustomLog ${APACHE_LOG_DIR}/greatsite.cakelampvm.com-access.log combined<br> Alias /statistics "/var/www/webwork.repository/webwork/maps_demo/webroot/statistics"<br> Include /etc/apache2/conf-library/basic-options.conf<br> Include /etc/apache2/conf-library/rewrite-enabling.conf<br></VirtualHost></pre>
254 <p>The above example is pre-modified for DNS Option A above, the
255 greatsite.cakelampvm.com name. Switching all of those to
256 "greatsite.tv" instead would support DNS option B.</p>
257 <p>Copy that file into /etc/apache/available-sites under an appropriate
258 name, which here we will call "greatsite.conf".</p>
259 <p>Tell apache to use the new file:</p>
260 <pre>a2ensite greatsite.conf</pre>
261 <p>Finally, restart apache to get it to begin serving the site:</p>
262 <pre>sudo service apache2 restart</pre>
263 <h3>Test the new web site</h3>
264 <p>Given the configuration above, your host PC should now be able to access
266 <p>To test this, first try pinging the hostname, e.g.: ping
267 greatsite.cakelampvm.com or ping greatsite.tv</p>
268 <p>Then, if there are responses to the ping, it means the DNS is
269 working. If there are no responses, check the instructions in the
270 above DNS option section.</p>
271 <p>Once the DNS is working, one can try browsing to the site at:
272 http://greatsite.cakelampvm.com or http://greatsite.tv (depending on the
273 DNS option chosen).</p>
274 <p>If the site is not showing up properly, try examining the apache logs for
275 error messages that can be corrected. The log files are stored in
276 /var/log/apache2 and are generally named after the website.</p>
277 <h2>Configuring the guest VM</h2>
278 <p>The guest VM should already be set up appropriately. These steps
279 are provided for reference and updates.</p>
280 <h3>Set up virtualbox guest additions for the VM</h3>
281 <p>** note for v001 of cakelampvm: the below steps are still needed on the
283 <p>This procedure is needed if the guest provides an older or incompatible
284 version of the guest additions (which have already been installed on the
285 guest vm). It may also be necessary when a new version of the guest
286 additions becomes available.</p>
288 <li>To install the guest additions, open the guest VM and have its window
290 <li>Choose the "Devices" menu and select "Insert Guest Additions CD
291 Image". This will mount the CD's ISO image on the VM.</li>
292 <li>On the guest VM, it may be necessary to mount the CD image that's now
294 sudo mount /dev/sr0 /media/cdrom</li>
295 <li>Since the VM currently has no windowing system installed, one must
296 start the Guest Additions install manually:<br>
298 sudo sh VBoxLinuxAdditions.run</li>
299 <li>This should install the guest additions.</li>
301 <h3>Set up network adapters on guest VM</h3>
302 <p>The network interfaces should already be configured on the guest within
303 the virtualbox configuration. This is available by clicking on the
304 VM in the virtualbox manager and selecting "Settings". These are the
305 configuration settings used:</p>
307 Attached to: Host-only Adapter<br>
308 Name: vboxnet0 <br>
310 Attached to: Nat Network<br>
311 Name: NatNetwork</p>
312 <p>On the guest VM itself, the network settings are specified in a file
313 called /etc/network/interfaces. Here are the current contents of
315 <pre>source /etc/network/interfaces.d/*<br><br>auto lo<br>iface lo inet loopback<br><br>auto enp0s3<br>iface enp0s3 inet static<br> address 10.28.42.20<br> netmask 255.255.255.0<br> network 10.28.42.0<br> broadcast 10.28.42.255<br> dns-domain cakelampvm.com<br> dns-search cakelampvm.com<br> dns-nameservers 127.0.0.1 8.8.8.8</pre>
316 <pre>auto enp0s8</pre>
317 <pre>iface enp0s8 inet dhcp</pre>
319 <h2>Handy Techniques</h2>
320 <h3>Get the network address on the guest vm</h3>
321 <p>Run this command: ifconfig</p>
322 <p>In the results, look for "inet addr". There may be more than one,
323 if there are multiple network interfaces.</p>
324 <h3>How to cleanly reboot or shut down the guest VM</h3>
325 <p>When you've got the DNS and everything integrated, these commands will
326 manage the vm's state:</p>
327 <p>First, log into the guest VM: ssh developer@cakelampvm.com</p>
328 <p>Then, reboot the guest VM: sudo reboot</p>
329 <p>Or, halt the guest VM: sudo shutdown -h now</p>
330 <p>Using these commands is better than just cycling the power from the
331 virtualbox control panel.</p>
332 <h2>Notes on building the Cake Lamp VM</h2>
333 <p>This is all work that should already have been done. It is
334 mentioned here just as breadcrumbs for a future vm builder.</p>
336 <li>Downloaded and installed virtualbox for host computer (where the vm
337 image will be built).</li>
338 <li>Downloaded ubuntu server 16.04 iso.
339 (https://www.ubuntu.com/download/server)</li>
340 <li>Created a new vm in virtualbox, telling it to start from the ubuntu
342 <li>Installed LAMP stack on guest VM. Some help here:
343 http://howtoubuntu.org/how-to-install-lamp-on-ubuntu</li>
344 <li>Configured CAKE on the guest VM. Useful link:
345 https://askubuntu.com/questions/628938/how-to-install-cakephp-in-ubuntu-14-04</li>
346 <li>Configured the two network adapters as needed (one for host-only
347 network and one for nat network). Here's some info about
348 virtualbox networking with two adapters similar to our setup:
349 https://askubuntu.com/questions/293816/in-virtualbox-how-do-i-set-up-host-only-virtual-machines-that-can-access-the-in<br>
351 <li>Installed and configured Samba service for the guest VM. The
352 main config file lives in "/etc/samba/smb.conf". Some pointers
354 https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20%28Command-line%20interface/Linux%20Terminal%29%20-%20Uncomplicated%2C%20Simple%20and%20Brief%20Way%21</li>