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-10</h3>
14 <h2>Basic info for the guest VM</h2>
16 <li>hostname: cakelampvm.com</li>
17 <li>local IP address: 10.28.42.20</li>
18 <li>services: DNS (bind9), apache2, fluxbox X windowing system, gnome
20 <li>main user: developer (password distributed separately)</li>
21 <li>mysql root password: (password distributed separately)</li>
23 <h2>How to set up virtualbox for your host PC</h2>
25 <li>Download and install virtualbox:
26 https://www.virtualbox.org/wiki/Downloads</li>
27 <li>Install the extension pack for virtualbox: This provides USB drivers
28 and other features. This is installed on virtualbox itself, not on
31 <li>Download the extension pack at
32 https://www.virtualbox.org/wiki/Downloads</li>
33 <li>Stop any running virtualbox vms.</li>
34 <li>Close virtualbox control panel.</li>
35 <li>Double-click on the downloaded extensions package (in a file
36 explorer) and virtualbox should install it.</li>
38 <li>Run the virtualbox control panel.</li>
39 <li>Download the cakelampvm guest vm package and unzip it. Store the
40 unzipped version in some appropriate place where you want the virtual
41 machine to reside on your host's hard drive.</li>
42 <li>Add the guest VM to your list of VMs. From the virtualbox menus,
43 choose the "Machine" menu and select "Add". Point the selector
44 dialog at the cakelampvm folder you created above and open the
45 cakelampvm.vbox file.</li>
46 <li>Now the cakelampvm should show up in the list of virtual
47 machines. Before starting it, perform the following network
48 configuration sections.</li>
50 <h3>Configure the Host-Only network on virtualbox</h3>
51 <p>Configuring host-only networking for the VM makes the VM completely local
52 to your machine. The cakelampvm will not be accessible on the
53 internet or from the LAN, and can only be accessed by your host PC.</p>
55 <li> Go to virtual box "Preferences" (global preferences, not for a
57 <li> Click on the "Network" tab.</li>
58 <li> Choose the "Host-only Networks" tab from within "Network".</li>
59 <li> Click the plus icon to add a new host-only network.</li>
60 <li>Set the "Adapter" parameters:<br>
61 IPv4 Address: 10.28.42.1<br>
62 IPv4 Network Mask: 255.255.255.0<br>
63 IPv6 Address: (leave blank)<br>
64 IPv6 Prefix Length: 0<br>
65 Virtualbox will fill in the other details like so:<br>
66 <p><img alt="host only network adapter" src="images/host_only_network_adapter.png"></p>
68 <li>Set the "DHCP Server Settings" to disabled, e.g.<br>
69 <img alt="host only dhcp" src="images/host_only_adapter_dhcp_server.png"><br>
70 This is disabled because we will be using statically assigned addresses
71 for convenience and stability.</li>
73 <p>Additional information on host-only (and other) network adapter types is
74 at: https://www.virtualbox.org/manual/ch06.html#network_nat_service<br>
76 <h3>Configure the Nat Network on virtualbox</h3>
78 <li> Go to virtual box "Preferences" (global preferences, not for a
80 <li> Click on the "Network" tab.</li>
81 <li> Choose the "Nat Networks" tab from within "Network".</li>
82 <li> Click the plus icon to add a new host-only network.</li>
83 <li>Set the "NAT Network Details" parameters:<br>
84 Network Name: NatNetwork<br>
85 Network CIDR: 10.0.2.0/24<br>
86 Supports DHCP: checked<br>
87 Supports IPv6: optionally checked<br>
88 These are my settings, with IPv6 left disabled:<br>
89 <img alt="nat net config" src="images/nat_network_config.png"></li>
91 <h2>Using the guest VM's DNS services</h2>
92 <p>The cakelampvm has been set up to provide a DNS server which will answer
93 name requests for all of the sites that the VM hosts.</p>
94 <p>To use the cakelampvm DNS, modify your host operating system network
95 configuration by adding or changing the DNS server to use the guest VM's
96 DNS service. This is available at the local address
97 10.28.42.20. The DNS server can be tested with nslookup, dig and
99 <p>Note that the cakelampvm DNS should be listed first, if one intends to
100 override any DNS names that actually exist out on the internet.</p>
101 <p>If the DNS server is properly set up, then these ping commands should get
102 answering responses:</p>
103 <pre>ping cakelampvm.com</pre>
104 <pre>ping defaultcake.cakelampvm.com</pre>
105 <pre>ping mapsdemo.cakelampvm.com</pre>
106 <h2>Editing files on the guest VM from the host</h2>
107 <p>On the host computer, look for the guest vm as a networked computer
108 called cakelampvm. This should provide some network shares using
109 Microsoft SMB protocol, and they can be attached to using the "developer"
110 user and its password.</p>
111 <p>On windows, one may want to mount this network location as a drive letter
112 for easier access.</p>
113 <p>Currently, the root of all web servers is exposed as "www". Editing
114 the files in those folders requires ownership by the developer user.
115 Currently the defaultcake server is owned by developer.</p>
116 <p>One should be able to create a new directory in the www folder owned by
117 the developer user over the network also, which can be used for creating
118 new projects. However, there is a config issue in the current vm
119 (v001) about this; to fix, run this command on the guest vm as the
121 <pre>sudo chmod g+w /var/www</pre>
122 <p>Afterwards, the www folder should allow the developer user to create new
124 <h2>Accessing files on the host PC from the guest VM</h2>
125 <p>If you want to share a folder from the host to the guest, perhaps for
126 driver updates or other conveniences, then make the share with these
129 <li>Create a folder on the host that is to be shared.</li>
130 <li>Right-click on the vm in virtualbox manager and choose "Settings".</li>
131 <li>In the "Shared Folders" tab of the settings, go to "Machine Folders".</li>
132 <li>Click the folder plus icon to create a new share.</li>
133 <li>Fill in the "Folder Path" on the host PC to the folder that will be
134 shared, and give it a name for the guest. We assume the folder
135 name will be "myshare".</li>
136 <li>On the guest vm, run the following commands to mount the share:<br>
137 <pre>mkdir ~/shared # for the guest's version of the shared folder</pre>
138 <pre>sudo mount -t vboxsf myshare ~/shared # mount the vm's share name onto the folder on the vm.</pre>
141 <h2>Adding a new website and domain on the guest VM</h2>
142 <p>To add a new website, you will need to pick one of the DNS options below
143 (A or B) depending on how you want to name the site. After the DNS
144 is updated, then follow the section after for creating a new apache conf
146 <p>Assuming one has created a new folder in "www" called "greatsite", then
147 the new web site can be brought online on the vm with one of the following
149 <h3>DNS Option A: Using a sub-domain in the cakelampvm.com domain</h3>
150 Connect to the cakelampvm via ssh as the developer user, e.g.: ssh
151 developer@cakelampvm.com
152 <p>Execute the following command to edit the DNS file for the cakelampvm
154 <pre>sudo vi /etc/bind/cakelampvm.com.conf</pre>
155 <p>Add a stanza for the new site at the end of this file:</p>
156 <pre>greatsite.cakelampvm.com IN A 10.28.42.20<br> IN HINFO "linux server" "ubuntu"</pre>
157 <p>Restart the DNS server: sudo service bind9 restart</p>
158 <p>Afterwards, pinging greatsite.cakelampvm.com should work from either the
159 guest or the host.</p>
160 <h3>DNS Option B: Using an entirely new domain for the site</h3>
161 <p>Similar procedure to above, but we will create a new file for the new
162 domain and add it to the bind directory. For this example, we will
163 create a file called /etc/bind/greatsite.tv.conf for our new domain
164 greatsite.tv with these contents:</p>
165 <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>
166 The gnarly prefix stuff above the "greatsite.tv." listing establishes
167 configuration info for the new domain. This file relies on the
168 existing cakelampvm.com infrastructure in DNS, such as the "ns" host, which
169 is the domain's name server.
170 <p>Now that the config file is in place, edit "named.conf.local" to add the
171 new file by adding this bit of configuration at the end:</p>
172 <pre>zone "greatsite.tv" in {<br> file "/etc/bind/greatsite.tv.conf";<br> type master;<br> allow-query { any; };<br>};</pre>
173 <p>Restart the DNS server: sudo service bind9 restart</p>
174 <p>Afterwards, pinging greatsite.tv should work from either the guest or the
176 <h3>Create a new apache configuration file and load it</h3>
177 <p>Start with the following template file for the new website, and modify it
178 for the appropriate host name:</p>
179 <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>
180 <p>The above example is pre-modified for DNS Option A above, the
181 greatsite.cakelampvm.com name. Switching all of those to
182 "greatsite.tv" instead would support DNS option B.</p>
183 <p>Copy that file into /etc/apache/available-sites under an appropriate
184 name, which here we will call "greatsite.conf".</p>
185 <p>Tell apache to use the new file:</p>
186 <pre>a2ensite greatsite.conf</pre>
187 <p>Finally, restart apache to get it to begin serving the site:</p>
188 <pre>sudo service apache2 restart</pre>
189 <h3>Test the new web site</h3>
190 <p>Given the configuration above, your host PC should now be able to access
192 <p>To test this, first try pinging the hostname, e.g.: ping
193 greatsite.cakelampvm.com or ping greatsite.tv</p>
194 <p>Then, if there are responses to the ping, it means the DNS is
195 working. If there are no responses, check the instructions in the
196 above DNS option section.</p>
197 <p>Once the DNS is working, one can try browsing to the site at:
198 http://greatsite.cakelampvm.com or http://greatsite.tv (depending on the
199 DNS option chosen).</p>
200 <p>If the site is not showing up properly, try examining the apache logs for
201 error messages that can be corrected. The log files are stored in
202 /var/log/apache2 and are generally named after the website.</p>
203 <h2>Configuring the guest VM</h2>
204 <p>The guest VM should already be set up appropriately. These steps
205 are provided for reference and updates.</p>
206 <h3>Set up virtualbox guest additions for the VM</h3>
207 <p>** note for v001 of cakelampvm: the below steps are still needed on the
209 <p>This procedure is needed if the guest provides an older or incompatible
210 version of the guest additions (which have already been installed on the
211 guest vm). It may also be necessary when a new version of the guest
212 additions becomes available.</p>
214 <li>To install the guest additions, open the guest VM and have its window
216 <li>Choose the "Devices" menu and select "Insert Guest Additions CD
217 Image". This will mount the CD's ISO image on the VM.</li>
218 <li>On the guest VM, it may be necessary to mount the CD image that's now
220 sudo mount /dev/sr0 /media/cdrom</li>
221 <li>Since the VM currently has no windowing system installed, one must
222 start the Guest Additions install manually:<br>
224 sudo sh VBoxLinuxAdditions.run</li>
225 <li>This should install the guest additions.</li>
227 <h3>Set up network adapters on guest VM</h3>
228 <p>The network interfaces should already be configured on the guest within
229 the virtualbox configuration. This is available by clicking on the
230 VM in the virtualbox manager and selecting "Settings". These are the
231 configuration settings used:</p>
233 Attached to: Host-only Adapter<br>
234 Name: vboxnet0 <br>
236 Attached to: Nat Network<br>
237 Name: NatNetwork</p>
238 <p>On the guest VM itself, the network settings are specified in a file
239 called /etc/network/interfaces. Here are the current contents of
241 <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>
242 <pre>auto enp0s8</pre>
243 <pre>iface enp0s8 inet dhcp</pre>
245 <h2>Handy Techniques</h2>
246 <h3>Get the network address on the guest vm</h3>
247 <p>Run this command: ifconfig</p>
248 <p>In the results, look for "inet addr". There may be more than one,
249 if there are multiple network interfaces.</p>
250 <h3>How to cleanly reboot or shut down the guest VM</h3>
251 <p>When you've got the DNS and everything integrated, these commands will
252 manage the vm's state:</p>
253 <p>First, log into the guest VM: ssh developer@cakelampvm.com</p>
254 <p>Then, reboot the guest VM: sudo reboot</p>
255 <p>Or, halt the guest VM: sudo shutdown -h now</p>
256 <p>Using these commands is better than just cycling the power from the
257 virtualbox control panel.</p>
258 <h2>Notes on building the Cake Lamp VM</h2>
259 <p>This is all work that should already have been done. It is
260 mentioned here just as breadcrumbs for a future vm builder.</p>
262 <li>Downloaded and installed virtualbox for host computer (where the vm
263 image will be built).</li>
264 <li>Downloaded ubuntu server 16.04 iso.
265 (https://www.ubuntu.com/download/server)</li>
266 <li>Created a new vm in virtualbox, telling it to start from the ubuntu
268 <li>Installed LAMP stack on guest VM. Some help here:
269 http://howtoubuntu.org/how-to-install-lamp-on-ubuntu</li>
270 <li>Configured CAKE on the guest VM. Useful link:
271 https://askubuntu.com/questions/628938/how-to-install-cakephp-in-ubuntu-14-04</li>
272 <li>Configured the two network adapters as needed (one for host-only
273 network and one for nat network). Here's some info about
274 virtualbox networking with two adapters similar to our setup:
275 https://askubuntu.com/questions/293816/in-virtualbox-how-do-i-set-up-host-only-virtual-machines-that-can-access-the-in<br>
277 <li>Installed and configured Samba service for the guest VM. The
278 main config file lives in "/etc/samba/smb.conf". Some pointers
280 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>