Objective: Set up a local website on a Windows 7 client with a Ubuntu / VirtualBox / Vagrant solution as an alternative to XAMPP.

Get a bootable Ubuntu DVD

VirtualBox requires a DVD containing an Ubuntu image.

* Load a write-once DVD in the DVD burner
* The Ubuntu download page is http://www.ubuntu.com/download/server
* Download ubuntu-14.04.1-desktop-amd64.iso (980 MB, version 14.04)
* Burn this image to the DVD

Install VirtualBox

Vagrant requires VirtualBox

* The Virtual Box download page is https://www.virtualbox.org/wiki/Downloads
* Download VirtualBox-4.3.20-96997-Win.exe and install
* Open the Oracle VM VirtualBox Manager and create a new virtual machine by clicking new.
* Select as name Ubuntu, type: linux and version Ubuntu (64bit)
* choose adding a virtual hard drive and VDI and fixed size of 10 GB (with dynamic allocation Ubuntu installation failed)
* As storage select an empty DVD (under controller: IDE) and select the Ubuntu image. It is easy miss the little DVD logo you are supposed to click
* Run Ubuntu from the manager.
* Allow Ubuntu to boot up, a welcome screen opens
* In the particular configuration used for this demonstration the mouse works simultaneously for both Windows screens and the Ubuntu screen, otherwise release the mouse from the Ubuntu screen via the Right Ctrl key
* In the Ubuntu opening screen click “install Ubuntu”, requires at least 6.5 GB of available drive space
* Select the installation type: Ubuntu reports that “this computer currently has no detected operating systems, what would you like to do?”. Even though it looks scary select the “erase disk and install ubuntu” option. It is a virtual environment inside Windows and not Windows itself after all.
* As soon as you remove the DVD, in the settings the DVD option is once again empty, the next boot up takes place from the hard drive

Install Vagrant

Windows and Ubuntu require a shared folder

* download vagrant 1.7.1. (vagrant_1.7.1.msi) via Windows Installer Windows version Universal (32 and 64 bit)
* Vagrant is located in C:\HashiCorp\Vagrant\bin
* Create folder C:\vm\test. This folder will be the shared folder between host (Windows) en guest (Ubuntu) machine.
* open cmd.exe with shift / right click in this folder
* The command vagrant init will start the server and create a configuration file called Vagrantfile
* The command vagrant init ubuntu/trusty64 will install an Ubuntu environment. Trusty64 is the official box for the Ubuntu Server 14.04 LTS
* Start the Virtual Machine (VM) with vagrant up.
* This will bring the VM up with the virtualbox provider
* A lot of installation goes on but in the end the message “Machine Booted and ready”
* At this stage, an opened VirtualBox manager would display a running VM starting with the name test_default_

SSH setup

From Windows we need to access the Ubuntu environment

* Enter the command vagrant ssh-config
* The output shows that a private key is stored in C:/vm/test/.vagrant/machines/default/virtulbox/private_key, the username is vagrant and the port is 2222.
* In PuTTY the host is 127.0.0.1, the username and password are both vagrant and the port is 2222.
* Open puttygen.exe and load the private key called private_key in C:/vm/test/.vagrant/machines/default/virtualbox
* Save as public key with the name vagrant_public_key.pkk
* Use this public key as key in the PuTTY SSH configuration. Set the host to vagrant@127.0.0.1
* An SSH session without using login credentials is now enabled.

Webserver setup

We need the Apache2 webserver running on the VM.

* Enter the command sudo apt-get install apache2
* Verify the Apache deamon is present: ls -la /etc/init.d/apache2
* Start Apache: sudo service apache2 restart
* Or even better, install the LAMP stack in one go: sudo apt-get install lamp-server^
* Verify presence of PHP: whereis PHP

Host setup

* Open the file called Vagrantfile in the shared folder
* Uncomment the line: config.vm.network “forwarded_port”, guest: 80, host: 8080 and reload vagrant (enter the command vagrant reload in the cmd.exe)
* Open the url http://localhost:8080/ in your browser
* It should display the content of /var/www/html/index.html in the guest invironment
* Next add the line config.vm.synced_folder “html”, “/var/www/html” and reload vagrant. The www folder is now a shared folder.

Mission accomplished. The host folder c:/vm/test/html is now shared with the guest folder /var/www/html. Any change to the index.html file, it does not matter if the edit is made in the guest or the host, will be visible in http://localhost:8080

Day to day usage

* In explorer find C:\vm\test
* open cmd.exe with shift / right click in this folder
* Enter the command vagrant up
* access Ubuntu server via SSH
* Access files via explorer

Set up a new host

* To vagrantfile add the line config.vm.synced_folder "project", "/var/www/project.localhost"
* vragrant reload
* sudo mkdir -p /var/www/project.localhost/public_html
* chmod vagrant:vagrant /var/www/project.localhost
* cd /etc/apache2/sites-available
* sudo cp 000-default.conf project.localhost.conf

Set up the hostfile with

vi project.localhost.conf

as:

tag VirtualHost *:80 tag

ServerName project.localhost
ServerAdmin postmaster@project.localhost
DocumentRoot /var/www/project.localhost/public_html
ServerAlias http://www.project.localhost

 

tag VirtualHost /tag

Next:
* sudo a2ensite project.localhost.conf
* service apache2 reload
* in Windows host file add: 127.0.0.1 project.localhost
* View site in browser as: http://project.localhost:8080/

Verified: upgrade from Windows7 to Windows10:

vagrant box update

Links

* http://www.sitepoint.com/getting-started-vagrant-windows/
* http://www.psychocats.net/ubuntu/virtualbox
* https://help.ubuntu.com/community/BurningIsoHowto
* http://askubuntu.com/questions/142549/how-to-install-ubuntu-on-virtualbox
* https://help.ubuntu.com/community/ApacheMySQLPHP
* https://serversforhackers.com/getting-off-of-mamp/
* https://www.andrewmunsell.com/blog/development-environments-with-vagrant-and-puppet

Advertisements