The cakelampvm VM:
Configuration and Usage

By Chris Koeritz

Vintage: cakelampvm v002    Updated: 2017-11-16

The cakelampvm project provides a virtualbox VM that acts as an "internet in a bottle".  The virtual machine provides DNS services (bind9), a Web server (Apache2), a full Ubuntu Linux desktop environment, the Fluxbox X window manager, and a suite of tools called the Feisty Meow® codebase .  Together, these services provide you with a very flexible and powerful testbed for web development, especially suited for CakePHP.

todo: arrange gritty details to back.

TOC GOES HERE.

Guest VM Configuration

Powering up with the Feisty Meow® scripts

[First, let me drop the registered trademark symbol from here on in.  I hope its presence above has been sufficiently clear for legal purposes, but now it will just get in the way.  Also, capitalization really bores me, and it's the feisty meow codebase anyhow, so that's how it will be written henceforth.]

The feisty meow scripts are a cohesive bash scripting environment for getting a variety of tasks done.  The scripts recently incorporated the 'avbash' collection from Saco Designs, which provides tools for bringing up CakePHP web sites and managing the collection of repositories for those sites.  Each website is considered an "application", and the application name itself (e.g. "winterportlibrary") can often provide all the details for "powering up" the site.  The feisty meow team has added additional scripts for managing DNS domains and Apache websites that provide the capability to "stand up" an entire website around an application, with accompanying domain.

The scripts for now are documented separately within the Feisty Meow codebase.  The Feisty Meow readme file provides some valuable information on configuring the codebase.  If you have the cakelampvm, then this has already been done for you on the vm in the developer account.  The script documentation is available in the UHHHHHH page of something..

How to set up virtualbox for your host PC

  1. Download and install virtualbox: https://www.virtualbox.org/wiki/Downloads
  2. Install the extension pack for virtualbox: This provides USB drivers and other features.  This is installed on virtualbox itself, not on the guests.
    1. Download the extension pack at https://www.virtualbox.org/wiki/Downloads
    2. Stop any running virtualbox vms.
    3. Close virtualbox control panel.
    4. Double-click on the downloaded extensions package (in a file explorer) and virtualbox should install it.
  3. Run the virtualbox control panel.
  4. Download the cakelampvm guest vm package and unzip it.  Store the unzipped version in some appropriate place where you want the virtual machine to reside on your host's hard drive.
  5. Add the guest VM to your list of VMs.  From the virtualbox menus, choose the "Machine" menu and select "Add".  Point the selector dialog at the cakelampvm folder you created above and open the cakelampvm.vbox file.
  6. Now the cakelampvm should show up in the list of virtual machines.  Before starting it, perform the following network configuration sections.

Configure the Host-Only network on virtualbox

Configuring host-only networking for the VM makes the VM completely local to your machine.  The cakelampvm will not be accessible on the internet or from the LAN, and can only be accessed by your host PC.

  1. Go to virtual box "Preferences" (global preferences, not for a specific vm).
  2. Click on the "Network" tab.
  3. Choose the "Host-only Networks" tab from within "Network".
  4. Click the plus icon to add a new host-only network, or if there is already a Host-only network, then edit it.
  5. Set the "Adapter" parameters:
    IPv4 Address: 10.28.42.1
    IPv4 Network Mask: 255.255.255.0
    IPv6 Address: (leave blank)
    IPv6 Prefix Length: 0
    Virtualbox will fill in the other details like so:

    host only network adapter

  6. Set the "DHCP Server Settings" to disabled, e.g.
    host only dhcp
    This is disabled because we will be using statically assigned addresses for convenience and stability.

Additional information on host-only (and other) network adapter types is at: https://www.virtualbox.org/manual/ch06.html#network_nat_service

Configure the Nat Network on virtualbox

  1. Go to virtual box "Preferences" (global preferences, not for a specific vm).
  2. Click on the "Network" tab.
  3. Choose the "Nat Networks" tab from within "Network".
  4. Click the plus icon to add a new host-only network.
  5. Set the "NAT Network Details" parameters:
    Network Name: NatNetwork
    Network CIDR: 10.0.2.0/24
    Supports DHCP: checked
    Supports IPv6: optionally checked
    These are my settings, with IPv6 left disabled:
    nat net config

Start up the VM

Using the virtualbox interface, you should now be able to start your virtual machine.  Virtualbox will complain if it detects any remaining configuration problems in the VM, but it should start normally.  The Linux boot sequence will show many lines of text, before bringing up a black console window with a login dialog.

You can log in directly on the VM console with the developer account, but it is generally more useful to connect to the cakelampvm over ssh.  If the networking has been established properly, you should be able to do this with:

ssh developer@cakelampvm.com  (or equivalent with your ssh client)

And then provide the password to log in.

A feature called "X forwarding" is enabled, so if you start graphical applications on the VM, you can display them from an appropriately configured host.  (If you're running Linux as the host for the VM, you can definitely run remote windows.  Windows may not support that.)

#### check this!!!

Using the guest VM's DNS services

The cakelampvm has been set up to provide a DNS server which will answer name requests for all of the sites that the VM hosts.

To use the cakelampvm DNS, modify your host operating system network configuration by adding or changing the DNS server to use the guest VM's DNS service.  This is available at the local address 10.28.42.20.  The DNS server can be tested with nslookup, dig and other tools.

Note that the cakelampvm DNS should be listed first, if one intends to override any DNS names that actually exist out on the internet.

If the DNS server is properly set up, then these ping commands should get answering responses:

ping cakelampvm.com
ping defaultcake.cakelampvm.com
ping mapsdemo.cakelampvm.com

Setting up DNS on Windows

The ipconfig tool will provide helpful information about your current networking and DNS configuration:

ipconfig --all

The DNS configuration on Windows is somewhat byzantine.  The pipe characters ('|') below are used to separate the menus or tabs or dialogs to traverse.  Follow this path to get to the DNS config:

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




Editing files on the guest VM from the host

On the host computer, look for the guest vm as a networked computer called cakelampvm.  This should provide some network shares using Microsoft SMB protocol, and they can be attached to using the "developer" user and its password.

On windows, one may want to mount this network location as a drive letter for easier access.

Currently, the root of all web servers is exposed as "www".  Editing the files in those folders requires ownership by the developer user.  Currently the defaultcake server is owned by developer.

One should be able to create a new directory in the www folder owned by the developer user over the network also, which can be used for creating new projects.  However, there is a config issue in the current vm (v001) about this; to fix, run this command on the guest vm as the developer user:

sudo chmod g+w /var/www

Afterwards, the www folder should allow the developer user to create new folders at will.

Accessing files on the host PC from the guest VM

If you want to share a folder from the host to the guest, perhaps for driver updates or other conveniences, then make the share with these steps:

  1. Create a folder on the host that is to be shared.
  2. Right-click on the vm in virtualbox manager and choose "Settings".
  3. In the "Shared Folders" tab of the settings, go to "Machine Folders".
  4. Click the folder plus icon to create a new share.
  5. Fill in the "Folder Path" on the host PC to the folder that will be shared, and give it a name for the guest.  We assume the folder name will be "myshare".
  6. On the guest vm, run the following commands to mount the share:
    mkdir ~/shared    # for the guest's version of the shared folder
    sudo mount -t vboxsf myshare ~/shared    # mount the vm's share name onto the folder on the vm.

Adding a new website and domain on the guest VM

To add a new website, you will need to pick one of the DNS options below (A or B) depending on how you want to name the site.  After the DNS is updated, then follow the section after for creating a new apache conf file.

Assuming one has created a new folder in "www" called "greatsite", then the new web site can be brought online on the vm with one of the following options.

DNS Option A: Using a sub-domain in the cakelampvm.com domain

Connect to the cakelampvm via ssh as the developer user, e.g.: ssh developer@cakelampvm.com

Execute the following command to edit the DNS file for the cakelampvm domain:

sudo vi /etc/bind/cakelampvm.com.conf

Add a stanza for the new site at the end of this file:

greatsite.cakelampvm.com    IN A    10.28.42.20
        IN HINFO "linux server" "ubuntu"

Restart the DNS server: sudo service bind9 restart

Afterwards, pinging greatsite.cakelampvm.com should work from either the guest or the host.

DNS Option B: Using an entirely new domain for the site

Similar procedure to above, but we will create a new file for the new domain and add it to the bind directory.  For this example, we will create a file called /etc/bind/greatsite.tv.conf for our new domain greatsite.tv with these contents:

$TTL 1W
@       IN SOA          @       fred.cakelampvm.com. (
                        2017100801      ; serial
                        2H              ; refresh
                        8M              ; retry
                        14D             ; expiry
                        6H )            ; minimum

        IN NS           ns.cakelampvm.com.
        IN MX   10      mail.cakelampvm.com.

# main domain for machine.
greatsite.tv.                 IN A            10.28.42.20
                              IN HINFO        "linux server" "ubuntu"
The gnarly prefix stuff above the "greatsite.tv." listing establishes configuration info for the new domain.  This file relies on the existing cakelampvm.com infrastructure in DNS, such as the "ns" host, which is the domain's name server.

Now that the config file is in place, edit "named.conf.local" to add the new file by adding this bit of configuration at the end:

zone "greatsite.tv" in {
        file "/etc/bind/greatsite.tv.conf";
        type master;
        allow-query { any; };
};

Restart the DNS server: sudo service bind9 restart

Afterwards, pinging greatsite.tv should work from either the guest or the host.

Create a new apache configuration file and load it

Start with the following template file for the new website, and modify it for the appropriate host name:

<VirtualHost *:80>
    ServerName greatsite.cakelampvm.com
    ServerAlias greatsite.cakelampvm.com *.greatsite.cakelampvm.com
    DocumentRoot /var/www/greatsite
    ErrorLog ${APACHE_LOG_DIR}/greatsite.cakelampvm.com-error.log
    CustomLog ${APACHE_LOG_DIR}/greatsite.cakelampvm.com-access.log combined
    Alias /statistics "/var/www/webwork.repository/webwork/maps_demo/webroot/statistics"
    Include /etc/apache2/conf-library/basic-options.conf
    Include /etc/apache2/conf-library/rewrite-enabling.conf
</VirtualHost>

The above example is pre-modified for DNS Option A above, the greatsite.cakelampvm.com name.  Switching all of those to "greatsite.tv" instead would support DNS option B.

Copy that file into /etc/apache/available-sites under an appropriate name, which here we will call "greatsite.conf".

Tell apache to use the new file:

a2ensite greatsite.conf

Finally, restart apache to get it to begin serving the site:

sudo service apache2 restart

Test the new web site

Given the configuration above, your host PC should now be able to access the new website.

To test this, first try pinging the hostname, e.g.: ping greatsite.cakelampvm.com or ping greatsite.tv

Then, if there are responses to the ping, it means the DNS is working.  If there are no responses, check the instructions in the above DNS option section.

Once the DNS is working, one can try browsing to the site at: http://greatsite.cakelampvm.com or http://greatsite.tv (depending on the DNS option chosen).

If the site is not showing up properly, try examining the apache logs for error messages that can be corrected.  The log files are stored in /var/log/apache2 and are generally named after the website.

Configuring the guest VM

The guest VM should already be set up appropriately.  These steps are provided for reference and updates.

Set up virtualbox guest additions for the VM

** note for v001 of cakelampvm: the below steps are still needed on the shipped image.

This procedure is needed if the guest provides an older or incompatible version of the guest additions (which have already been installed on the guest vm).  It may also be necessary when a new version of the guest additions becomes available.

  1. To install the guest additions, open the guest VM and have its window in focus.
  2. Choose the "Devices" menu and select "Insert Guest Additions CD Image".  This will mount the CD's ISO image on the VM.
  3. On the guest VM, it may be necessary to mount the CD image that's now available:
    sudo mount /dev/sr0 /media/cdrom
  4. Since the VM currently has no windowing system installed, one must start the Guest Additions install manually:
    cd /media/cdrom
    sudo sh VBoxLinuxAdditions.run
  5. This should install the guest additions.

Set up network adapters on guest VM

The network interfaces should already be configured on the guest within the virtualbox configuration.  This is available by clicking on the VM in the virtualbox manager and selecting "Settings".  These are the configuration settings used:

Adapter 1:
  Attached to: Host-only Adapter
  Name: vboxnet0 

Adapter 2:
  Attached to: Nat Network
  Name: NatNetwork

On the guest VM itself, the network settings are specified in a file called /etc/network/interfaces.  Here are the current contents of that file:

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet static
  address 10.28.42.20
  netmask 255.255.255.0
  network 10.28.42.0
  broadcast 10.28.42.255
  dns-domain cakelampvm.com
  dns-search cakelampvm.com
  dns-nameservers 127.0.0.1 8.8.8.8
auto enp0s8
iface enp0s8 inet dhcp

Handy Techniques

Get the network address on the guest vm

Run this command: ifconfig

In the results, look for "inet addr".  There may be more than one, if there are multiple network interfaces.

How to cleanly reboot or shut down the guest VM

When you've got the DNS and everything integrated, these commands will manage the vm's state:

First, log into the guest VM: ssh developer@cakelampvm.com

Then, reboot the guest VM: sudo reboot

Or, halt the guest VM: sudo shutdown -h now

Using these commands is better than just cycling the power from the virtualbox control panel.

Notes on building the Cake Lamp VM

This is all work that should already have been done.  It is mentioned here just as breadcrumbs for a future vm builder.