Getting a Web Server to Run on a USB Drive
Focusing on Functionality and Compatibility
Recently we put a disaster preparedness kit that acted as a Drupal website on a usb thumb drive for the American Institute of Architects’ Communities by Design Initiative. This meant getting the entire Apache+php+MySQL stack running from the usb drive and essentially acting as a web server on a stick. Installing a web server is almost never as simple of a task as you’d expect no matter how often you do it, especially when it needs to be set it up on the fly from any computer.
There are several platforms that thankfully provide fully contained web server environments that make this process much easier. Among us Mac developers MAMP is very popular, and on the Windows side platforms like XAMMP and the Uniform Server work well. For this project we started from XAMMP, and it got us fairly close right out of the box. However, there were some drawbacks – it was big, and it assumed some things we didn’t like. So we made some performance tweaks, most importantly enabling and configuring a php cache, to speed things up. We also created some additional nice features like custom start up scripts and icons. With this, the server was set up for Windows users.
Here is a screencast showing how it runs off the stick. I’ll explain how we did it here to hopefully save other developers some time below.
Next we needed to set it up for Macs. We didn’t want to sacrifice any functionality on the Windows side when we set up the stick for Macs, since most users would access the kit from Windows. This is always a little tricky. We weren’t interested in providing two completely separate applications. We wanted the same information to be available for everyone, no matter if they used Windows or a Mac, and this means sharing the database and user files between both operating systems.
So we started with the MAMP package to get the kit working on Macs, and similarly to what we did with XAMMP, we stripped and reworked it to behave nicely on a usb stick. The MAMP package is hard coded to run from a very specific location on a Mac, and that location isn’t a usb disk. We needed to touch every configuration file and all of the MySQL and Apache start and stop scripts to make it work from the stick. Additionally there were some extra niceties in the MAMP package that we just removed, as we didn’t need them and they just took up space. One unexpected issue we came across was formatting the stick. Windows disk formats (FAT16 & FAT32) don’t work the same way as Mac and Unix disk formats, and very importantly they don’t have the notion of “sockets.” A socket is how two Unix programs talk to each other, and in our Apache+PHP+MySQLstack it’s how MySQL communicates with php. Without this link, Drupal can’t run.
So this could have been a show stopper for Mac compatibility, but we couldn’t have that. We discussed several possible solutions and eventually settled on adding an HFS+ partition to the USB sticks. This partition is totally invisible to Windows users and provides a place for MySQL to put its “socket.” And by sharing the FAT16 part of the drive, we’re able to share all the application files – both Drupal’s php files and the MySQL databases. This means that if you make an update on a PC, that same update will show up on a Mac. The only downside with this solution is that Mac users will see an empty disk on their desktop. We decided we could live with that for now.
Also, we found two shortcuts for the Mac version that are worth mentioning. For the PC version we’ve included Firefox Portable, as we’d really hate for anybody to have to use IE when there are alternatives. But on the Mac we let people just use their default browser (IE 5 really isn’t a threat anymore, and the site looks great in Safari) so didn’t need to include one on the stick. Secondly, on the PC we included a light PDF viewer called Sumatra because Adobe tends to take forever to load. The Mac operating system comes with a nice light PDF viewer so we didn’t need to include this in the Mac version.
In a few days, Earnest will write about some of the research that went into this decision and how our initial plan to use Resin didn’t work out once it was on the stick.
14 Comments
symbolic links (aliases)
This is indeed a great idea and got me working on an implementation. I'm using xampplite for win os, and xampp for mac.
Jeff, when you say you made lots of changes, does it mean that you made changes to the config files so that they now refer to the USB volume instead of the default installation location for MAMP (/Applications/MAMP)...
did you use relative paths when referring to the install locations on the USB volume or direct paths?
well i tried that method, and found it too time consuming and feeble, a slight mistake and it would break the system.
Instead i tried using symbolic links... in the original mamp startup script i added a function that would create a symblic link from /Applications/xampp to the USB volume's install location. And everything worked like a charm. I also added a function to delete the link from the shutdown script on mamp.
Just thought I'd share a soln that worked for me, in a much quicker manner, and also allowing me to update the the apps. in the future.
We used the delicate
We used the delicate relative path approach. I can confirm that it was a bit trying to get it working at first, and did require reworking all the startup scripts, but it did work for us eventually.
-jeff
very good idea
its really a great idea. I need such a solution long time ago!
webserver on a stick
Good job!
I really can't wait until it gets public because I really need a Portable Webserver!
Good luck.
MAMP on a stick?
I'm very interested in how you got MAMP running on a thumb drive. I'm teaching a class on Web Dev and due to strict University policies, we can't install AMP on the workstations.
Have you published how to change MAMP to work on a thumb drive? Or can you post your version of MAMP tricked out for a thumb drive?
many thanks
How to?
+1 vote for any more info on this - this blog entry seems to be the only place on the web describing MAMP (+LAMP +WAMP) on a USB drive. Do you have any more details you could make available?
many thanks
MAMP on a stick
I also would be very interested in this.
Thanks!
Thanks to all of you who caught that we had a bit of spam on this post! We'll keep a closer eye on it from now on.
Bonnie
Nice article. I'm actually
Nice article. I'm actually using this as inspiration to get my own "server-on-a-stick" version happening for a University project.
Just on the empty volume that mounts for Mac users, could you not set the invisible bit using SetFile?
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/...
I haven't actually tried
I haven't actually tried that. It's not a bad idea at all, but I wonder if it'll work on a volume.
Have you had a chance to try it?
More details, please!
I'm particulary interested in what kind of changes you did to XAMP.
What is your directory layout ?
Which scripts did you change/add ?
I'm working on a Drupal site and I would like to build a "portable Drupal dev kit" for my distributed team that would run on an USB stick.
There were a lot of changes
There were a lot of changes we made, but to address your specific questions;
Because we were using two different apache+php+mysql stacks we moved both the database and web root directories out of where they normally lived in xammp & mamp. We had a /data directory on the stick which had all the database and files for drupal.
Script-wise we wrote our own start and stop scripts. This allowed us to launch firefox portable after the services had stared, and also make some changes to config files on the fly.
Great idea
This is a great idea. There can be any number of uses for a self contained application such as this. Browser/User friendly without having to be your own admin. I hope you keep everyone updated on this and similar projects.
Thanks Steven :) We will
Thanks Steven :) We will blog more about this in the coming days, including how the backups are working, the option of using Resin as the server environment and why we ended up not doing that, and lastly a piece on how we set up google analytics to track usage of the sticks.