VulgarisOverIP

Handling Multiple Web Development Projects Using VMware

This morning a client that I’m currently developing for called me to inform me that they needed to use their web application immediately. I had to host it for them myself as they didn’t have their own server, but I was already working on another project that I was already hosting.

Normally this involves editting my httpd.conf file, adding a virtual server, messing with the firewall and restarting Apache. But today I decided to try something new: setup a VMware Workstation session running Ubuntu server and use the Shared Folders feature to link my project to the document root. I’ve been really pleased with the results and now, if I need to setup another server for a client, I can just clone my current session, share another project folder and it’s up in minutes.

For me, the biggest upside to doing it this way is that each application can assume they are running with default settings including standard HTTP/S ports. This means no fancy setup of name servers when you are trying to host multiple sites, each with SSL. Another nice thing is the added security between clients who are now partitioned into their own virtual servers and not having to restart Apache or MySQL for all your other projects. It’s real easy, here’s how I did it:

  1. Install VMware and get it running
    Go to , create a profile and get a VMware Workstation key, download the program and follow the instructions. Setting it up has never been a problem and is kind of beyond the scope of this article, just don’t forget to run vmware-config-tools.pl after installing it.
  2. Download Ubuntu Server and install it
    Head over to and follow the links to download the SERVER version of Ubuntu, the standard version has too much stuff we don’t need. Create a new VMware session (make sure to choose Linux, or specifically Ubuntu as the OS) and remove the sound and floppy hardware in the session settings. In the cdrom settings, make sure the device is pointed to the ISO you just downloaded. Boot up the machine and keep hitting enter until you’re done (you may to choose ‘yes’ instead of ‘no’ once during the partitioning sequence). I chose not to install the LAMP version because I’m going to download xampp to host the web site, but do whatever you’re more comfortable with. The whole installation process took about 10 minutes on my 2.6 GHz P4 dual-core with 2 gigs of RAM, but VMware’s cloning feature means you only have to go through this once. I suggest you update the system with a sudo apt-get upgrade upon logging on for the first time.
  3. Setup XAMPP (or roll your own LAMP)
    Over time I’ve found that downloading xampp, untarring it, and running sudo /opt/lampp/lampp start is a lot easier than setting up Apache, PHP and MySQL seperately. The easiest way to download xampp to the Ubuntu server session is to find a mirror from sourceforge and use wget. For example, here’s how I installed it from the command prompt:wget http://superb-west.dl.sourceforge.net/sourceforge/xampp/xampp-linux-1.5.4.tar.gz
    sudo tar xvfz xampp-linux-1.5.4.tar.gz -C /opt
    sudo /opt/lampp/lampp start
  4. Setup the shared folder for the document root
    Before you can install VMware tools and allow folders to be shared, you have to download the right tools. Enter this at the command prompt:sudo apt-get install make gcc linux-headers-`uname -r` build-essential xinetd Now, to install VMware tools, on the menu bar click ‘VM’ and then ‘Install VMware Tools…’. This will load the tools on a CD on your session. To actually instally the tools run these commands:

    sudo mount /dev/cdrom cd /tmp tar zxf /media/cdrom0/vmware-linux-tools.tar.gz umount /dev/cdrom cd vmware-tools-distrib sudo ./vmware-install.pl

    To share the folder find the menu bar, click on ‘VM’, click on ‘Settings…’, click on ‘Options’, click on ‘Shared folders’ and finally click ‘Add…’. Enter a name for the folder, find your project directory and hit ‘OK’. Your project directory will now be located in the Ubuntu session at: /mnt/hgfs/[your project directory]. If you are using xampp, you can point your htdocs directory here by typing the following:

    sudo rm -rf /opt/lampp/htdocs sudo ln -s /mnt/hgfs/[your project directory] /opt/lampp/htdocs
    That’s it! If you don’t want to go through all the hastle again, I suggest you clone your VMware session now and just keep cloning it everytime you want to make a new server. To view the web site, just point your browser to the server’s IP address. Let me know what you think, I’m off to create a new session to host my own WordPress blog.

File Upload Widget for the Google Web Toolkit

It’s been a while but now that school is done kicking my ass I’ve turned my attention back to my beautiful web applications. Recently I’ve been doing a lot of work with the Google Web Toolkit [http://code.google.com/webtoolkit]. It’s turned my hatred of Javascript and AJAX into a renewed love affair with Java and Google.

Basically, the toolkit let’s me write complicated, messy Javascript in beautiful Java that will work on any browser (99.9% of the time). The toolkit is full of awesome feature including easy to use RPC classes, GUI widgets that look and work the same across browsers, and even a native interface to work with Javascript (if you absolutely have to).

Enough with the details and praise, check the GWT website if you have more questions, it’s time for some useful code. I plan on writing a bunch of articles on some classes I’ve written, but today I’m going to start with something simple: a file upload widget. The GWT has a widget for just about every HTML element except file upload. It’s totally understandable because a well written widget would require the creation of some sort of complicated backend (script or applet) and that would ruin some of the purity of the GWT solution.

OK, time for some code:

import com.google.gwt.user.client.ui.*; import com.google.gwt.user.client.*;

public class FileUpload extends Widget {

private class UploadFrame extends Frame {

public UploadFrame(String name) { this(name, null); }

public UploadFrame(String name, String url) { super(url); DOM.setAttribute(getElement(), "name", name); DOM.setStyleAttribute(getElement(), "width", "0"); DOM.setStyleAttribute(getElement(), "height", "0"); DOM.setStyleAttribute(getElement(), "border", "0"); }

}

private Element form = DOM.createElement("form"); private Element fileUpload = DOM.createElement("input");

public FileUpload(String name, String action) { setElement(form); DOM.setAttribute(form, "action", action); DOM.setAttribute(form, "method", "POST"); DOM.setAttribute(form, "enctype", "multipart/form-data"); DOM.setAttribute(form, "target", name); DOM.setAttribute(fileUpload, "name", name); DOM.setAttribute(fileUpload, "type", "file"); DOM.appendChild(form, fileUpload); DOM.appendChild(RootPanel.getBodyElement(),(new UploadFrame(name)).getElement()); }

public FileUpload(String name) { this(name, ""); }

public void setAction(String action) { DOM.setAttribute(form, "action", action); }

public String getAction() { return DOM.getAttribute(form, "action"); }

public Element getElement() { return form; }

public native void upload() /*-{ this.@com.application.client.FileUpload::getElement()().submit(); }-*/;

}

A few caveats:

  1. This widget offers no feedback to the GWT application of the upload status. This could be remedied by some sort of RPC to the backend. I only used this class to upload some batch data and give back a processed file.
  2. Any references to com.application should be changed to reflect your own application hierarchy.

Just append this widget to some container in your application and execute the upload() method when it’s time to upload (most likely after pushing some sort of upload button).

Piece of cake right? Please email me with suggestions and other solutions while I fix/update my last posting.

Send Email With PHP and GMail Hosted for Your Domain

I’ve been using Linux ever since I became a CS major at Georgia Tech five years ago. I’ve compiled my own kernels, maintained Apache and MySQL, and written custom IPTable’s; I’ve even setup printing AND scanning with modern hardware. But not once have I ever come close to setting up a working mail server.

On second though, I think I may have come close once. I sent out an email to myself and then sat there at my GMail inbox hitting refresh, waiting to receive the message. About five minutes later I found it in the spam folder and started reading about reverse IP pointers and DomainKeys. My brain started to hurt and in the end, I was sending messages through godaddy.com’s email servers and hoping most of my customers got their emails.

Now that GMail for your domain has arrived (if you’re a lucky beta winner, that is) it’s like hiring a world-class email server engineer and paying them nothing. It takes a little work because of GMail’s security requirements, but you end up with a rock solid email server that won’t send messages straight into spam folders.

First, download the standard PHPMailer libraries (version 1.73). The only thing you have to modify is the class.smtp.php file. Open it and go down to about line 683, in the Quit() member function. Comment out everything between the fputs() that sends the “quit” command and the if statement surrounding $this->Close() except for $rval = true;. The reason this works is unknown to me, but every time I tried to read from the socket after sending the “quit” command I got a lot of garbage.

Now just use the following settings:

$mail->From = '***@&&&.com';
$mail->Mailer = 'smtp';
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = '***@&&&.com';
$mail->Password = '***';

Replace the *’s and &’s for real values and you’re all set.