When it was time to retire my 3-year-old Dell Inspiron laptop, I decided to buy an Asus Eee PC netbook. I did all my web application development on the laptop, whereby the application and development environment were on the hard drive. Although the netbook's hard drive is large enough to contain everything, I decided to take this opportunity to try putting a running web server along with a large, database-driven web application on a portable drive. I would reinstall the development environment on my netbook, but put the web server and application on the portable drive.
The main advantage of a portable drive is not development, but demonstrations in situations where the Internet is not available or either very slow or very expensive. I can just copy the portable drive to another portable drive (I need the first one for development) and use it myself or give it to the person going to the trade show. Since I won't be the only one doing demonstrations, the web server needs to be easy to start. Previously, I would ask to have the other person's laptop for a few days to get the pre-installed web server and application up-to-date. I had to be sure several installations on several laptops were at the same stage of development. Now I just delete everything and copy from the master installation.
Instead of migrating I could have downloaded the latest version of XAMPP and installed it on the portable drive. However, I wanted to be sure all the versions of the various components and all settings in all the configuration files were the same as on my development system in order to avoid unpleasant surprises.
XAMPP is small enough to put on a 4 or 8 GB USB flash drive with 2.5 to 3 GB for all its files, but my application with all its media files needs several times that, so I bought a 250 GB external USB hard drive for the purpose.
Here are the steps I took to migrate my XAMPP web server and applications from a Windows PC hard drive to a portable drive. It should also work with any other Winsows-Apache-MySQL-PHP system. My terminology is from Windows XP, but everything should work analogously for Windows Vista.
* Make sure the portable drive is large enough for the XAMPP directory and any web documents not included in XAMPP directory.
* Copy the XAMPP directory and any web documents not included in the XAMPP directory and any directories in the PHP
include_path directive, for example, copy
C:\xampp\*.* to
E:\xampp\*.*
* If Apache or another web server like IIS is already running on the target system, you will need to disable it. For Apache, look for
xampp_stop.exe, usually in
C:\xampp, and run it. If Apache, MySQL or other modules are running as Windows services, it would probably be best to deactivate the services.
* Since the configuration files are (probably) full of drive letters, and portable drives are assigned drive letters dynamically, we need to remove the drive letters from the configuration files: Remove all occurrences of the source drive letter (usually
C:) in the following configuration files:
o
\xampp\apache\conf\httpd.conf
o
\xampp\apache\conf\extra\httpd-xampp.conf
o
\xampp\apache\conf\extra\httpd-ssl.conf
o
\xampp\apache\bin\php.ini
o
\xampp\mysql\bin\my.cnf
o Any other configuration files you use. Look in the directories above.
* The lines in the configuration files will be changed, for example, from '
ServerRoot "C:/xampp/apache"' to '
ServerRoot "/xampp/apache"'.
* Caution: Be sure NOT to run
\xampp\setup_xampp.bat. Otherwise the current drive letter of the application will be added to all the path names. This batch file is not meant for portable installations.
* Tip: If you don't see
.cnf file endings in Microsoft Explorer, and the icon for "
my", etc., looks like a small curved arrow, then Windows has associated the ending
.cnf with NetMeeting, and you can't edit the file by double-clicking or right-clicking it. Run your favorite text editor (for example,
Start > Run > Notepad) and open the file from within the editor or drag the file to the editor.
* Optionally export your favorites/bookmarks from the source machine, rename the file to
index.html, and put it in the root directory of the portable drive. The links to your web applications should have the form
http://localhost/(application/) and don't need to be changed, but if you have links to HTML files that were on the hard drive, they will no longer work. You can consider changing them to the most likely drive letter, perhaps
E:.
* Tip: A common conflict is Skype or another application listening on the same port as Apache, usually port 80. End the offending application or change the port Apache listens to (the
Listen directive in
\xampp\apache\conf\httpd.conf), or change the port the other application listens to. In Skype, for example, remove the checkmark next to "
Tools > Options > Advanced > Connections > Use port 80 and 443 as alternatives for incoming connections", depending on your version of Skype.
* Optionally create a batch file named
start.bat with the following contents, and put it in the root directory of the portable drive (this starts the XAMPP modules and then starts the bookmark file created above in the default browser):
cd \xampp\
start /min xampp_restart.exe
cd \
start index.html
* I created a second batch file called
start2.bat with the following contents:
@echo off
cd \xampp\
start /min xampp_restart.exe
\PrcView\pv.exe -r1 -d1000 apache.exe > nul
\PrcView\pv.exe -r1 -d1000 mysqld.exe > nul
start http://localhost/workspace/heli/index.php
This batch file uses a free utility you can find at
http://prcview.com to determine if Apache and MySQL are already running before starting a specific PHP application in the default browser (adapt to your situation). Be sure to include the PHP file in the last line (here "
index.php") because otherwise some systems may display a missing parameter error.
* Run
\xampp\xampp_restart.exe.
* If Windows Firewall asks whether it should continue blocking Apache HTTP Server or mysqld, reply with "
No longer block". You only need to do this once per PC.
* If you get any errors about not finding files, see the step above about removing drive letters in configuration files.
* Test the installation with
http://localhost in a browser.
* Optionally create a batch file named stop.bat with the following contents, and put it in the root directory of the portable drive (to be executed before removing the portable drive from the computer):
cd \xampp\
start /min xampp_stop.exe
* Optionally create a text file called
autorun.inf in the root directory with the following contents:
[autorun]
open=start2.bat
icon=\xampp\htdocs\application\favicon.ico
action=Name of Application
This will cause a menu item to be added at the top of the Autorun window that opens when you insert the drive into a PC. Adapt the three directives to your situation.
* Depending on the purpose at hand, you can change the "
open" directive to
start.bat or
start2.bat.
* Whoever is doing the demonstration needs to know not to close the minimized Apache application. To end the application, he/she must run
stop.bat. Not until then can the portable drive be removed. Don't forget to also click the little green arrow to remove the hardware safely as with all portable drives.
See the eHow version of this post here:
How to Migrate a Web Server From a Hard Drive to a Portable Drive