Arieh.co.il

When WAMP is not enough - Virtual Server Machine

This post has gone some heavy changes and modifications to make it more secure, usable and stable. I hope this will mean an all around better solution.

The Problem

For many reasons, no matter how many times I try to switch, I always end up returning to Windows. It has to do with a stable IE version (which means easy test environment), with availability of tools and with the feel of a solid GUI. Especially now with Windows 7, I rarely find myself looking for something that isn't fully available and supported for it.

I've been developing with WAMP for a very long time, and I've always been happy about it. But lately, I've been looking to expand my server-side knowledge. It started with Ruby on Rails, and now I'm looking at Node.js (which is awesome). The thing is, both of them are Unix based, and their Windows support, although existing, sucks. Traditionally, I would use my home server (an old machine running Debian), but for fast development, network drives simply don't cut it, and I really didn't want to give up my Windows habits.

The Solution - Virtual Machine

And so, I though to myself - why not just install a virtual machine running a lightweight server. If it can have a small enough footprint, I could actually stop using my WAMP, and with it running within my Windows, it will give me a much easier time adjusting (I've tried Cygwin and it's just not it).

So, I've set out to install my virtual server. After some poking around i chose Ubuntu Server, which seems like a good choice, as it has a huge supporting community. From there on it was all trial and error. To my surprise, although this idea is actually quite cool, I haven't found even one good guide on how to do this. So for next generation's sake - here is one guide on how to set up a Virtual Ubuntu server on your Windows machine.

In the end, what we will have is a lightweight development server that for all purposes functions just like your WAMP. You will be able to develop using all your familiar Windows tools on your Windows machine and interpreted at a Linux system.

I must say I was quite surprised at how good this works - I mean - I would expect this to be quite heavy, but it simply isn't.

Warning - Although I had more help with this version of the guide, it still might be lacking, especially security-wise. This is a guide on how you can create a WAMP replacement. It is meant for experimenting on you VM. Don't use it's advices on a really machine.

What you will need to get

  1. Virtual Box - our virtual machine software. Go ahead and install it.
  2. An Ubuntu Server ISO. Choose the 32bit, as Virtual Box runs a 32bit machine.
  3. hstart - a program that allows us to run "ghost" applications.
  4. PuTTy - an SSH client.

What next?

Installing Ubuntu

  1. First, create a new VM, but don't start it. Instead, go to Settings and Network.
  2. On Adapter 1 choose Bridged, and select the adapter you use to connect to the internet.
  3. On Adapter 2 choose Host-Only.
  4. Start the VM. In the machine menu, choose CD and mount the ISO file.
  5. During the installation you will be asked what packages to install. Choose LAMP and OpenSSH.
  6. After the installation, the machine will start. Login and leave it open.

Setting up the network:

  1. First, on Windows - Get to your network adapter settings. On Windows 7 - Start -> right-click on Network -> properties -> Change Adapter Settings. Find the Virtual-Box Host-Only adapter, right-click->properties. There, choose TCP/IPv4 and properties. You need to choose an IP - I chose 192.168.56.1. On Mask 255.255.255.0. leave the rest empty. Click OK and exit.
  2. You also need to enable sharing on your www folder and name it accordingly.
  3. On your VM, enter sudo nano /etc/hosts.
  4. Add a line that looks like this: 192.168.56.1 myserver where the IP is the IP you chose on the previous step and the name is whatever name you want to identify your Windows machine with.. Press Ctrl X and then Y to save the changes.
  5. Enter sudo nano /etc/network/interfaces. If you already have lines referring to eth1 delete them, and add the following:

            auto eth1
            iface eth1 inet static
                    address 192.168.56.2
                    netmask 255.255.255.0
            

    Where the address matches the one you used for Windows, only with a different last number.

To check if everything worked, restart your VM (sudo reboot). When it's back up, enter ping [WIN_NAME] (WIN_NAME being the name you chose for your windows machine). If everything worked you should be seeing packets being received.

Do the same thing with your Windows machine: Win-Key R -> cmd, then enter ping [SERVER_NAME].

Stetting up Sharing

  1. Enter the following code:

            sudo apt-get install smbfs cifs
            
  2. Next enter nano /home/[username]/.smb_crd where usename is your linux user name. You will need to enter 2 lines:

            username=Win_User
            password=password
            

    Where username and password match your Windows' user name and password. Exit and save.

  3. Enter sudo nano /etc/fstab. There, add the following line in the end:

            //windows_comp/www      /var/www  cifs  auto,credetials=/home/[username]/.smb_crd 0 0
            

    Where windows_comp is the Windows computer's name (the one you chose earlier), www the name of your shared folder and [username] your linux user name.

  4. Enter sudo shutdown -P now to turn off the machine.
  5. Back on windows, go to C:\Windows\System32\drivers\etc and open the hosts file. This one is the tween of the linux version. Enter a pair that matches the IP you gave to your linux machine and a name you want to identify it with. Save and restart your computer.

To see if this worked, start up your VM and enter cd /var/www, then dir. Here you should see all your www files listed.

Remote MySQL

You can skip this if using PHPMyAdmin is good enough for you. I myself am a GUI guy, so I want my usual software to work with the MySQL server. This require 2 steps:

  1. Edit /etc/mysql/my.cnf (sudo nano /etc/mysql/my.cnf), find the line that says bind-address and enter the IP you chose for your server (192.168.56.2). Save and exit.
  2. Run MySQL (mysql -P) and enter the following lines:
            use mysql;
            GRANT ALL PRIVILEGES ON * TO root@'192.168.56.1'; 
            exit;
            

    The IP being your Windows IP.

  3. sudo restart mysqld.

With this in check, you will be able to access your MySQL server using the server's IP.

Making the server run in the background

  1. While your VM is running, open PuTTY (from windows). In the address, enter your server's IP, enter a name under Saved Session and click save. Next, double click on the new session name. When asked about the certificate click ok. If all is well you should be able to log in. If nothing happened, you might need to install OpenSSH. Try and google it.
  2. Create a new text file and name it start_server.bat (I placed it in c:\). Right-click -> edit. Enter the following code:

            "C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe" -startvm [VM_NAME]
            

    Make sure the path is correct. Change [VM_NAME] to your VM name, save and exit.

    Double-click on the file to see it start up you VM. This will start it in "Silent Mode".

    To see if it worked, wait a while (you need the VM to finish boot), then try and access it via PuTTy. Turn it off (note- you can also turn it off via the Virtual Box's main interface).

  3. Now, create a shortcut for your hstart (I recommend saving it somewhere permanent. Don't simply leave it in the Downloads folder). Next, right-click->properties. Add /NOCONSOLE C:\path\to\start_server.bat (path leading to your bat file obviously). Apply.

    Opening this shortcut will run the server on the background. If you want, you can place it in the startup folder to make it start on boot.

Wrapping it up

With these last steps, we have an exact replicate of WAMP, running a linux machine. Remember though that it can be slower. But on the up-side - you will have a much stronger machine, capable of doing much much more than just running PHP and MySQL.

What we achieved here is quite remarkable - you now have access to a fully running, stable linux release on your Windows machine. I find it simply cool, and it's a very powerful tool, both for experimenting with other server-side technologies, and also for learning linux and it's usages.

I've had more help on this version than on the first version, but it still lacks some stuff, so i you have advices and comments on how to do things differently please let me know.

JavaScript Reference, JavaScript Guide, JavaScript API, JS API, JS Guide, JS Reference, Learn JS, JS Documentation