Sample config files
AMP on a USB ...whyfor ?
I dunno ;), there are several possible uses , the most obvious being demonstrating your wares to a potential client on their computer , but the possibilities should be obvious to any PHP heads who in general I find are quite an inventive bunch. In the past I have produced AMP CD-R's , e.g. Apache/MySQL/PHP installation running from a CD-R , a USB flash drive install is even easier since we don't have to worry about non-writable media, the point of this article by the way is to provide a portable system with no hard-coding of drive paths etc.
err a USB flash drive (min 32MB) , PHP (I am using 5.0.3 ), Apache (2.0.50) & MySQL -v $whatever , and the text editor of your choice, my tests are all done on XP & 2003 server , this configuration should however work on windows 2000 , and possibly on windows 98 though I won't bet anything I need on that.
32MB ? , OK ever-so slightly stripped versions of the above configurations take 29.4MB of space on your USB , most 32MB USB's use a couple of MB for whatever (often rescue software etc) so you may need to strip say some unused language files to give you a MB or 2 for your project , in fact you can get well below 15MB if you are really stingy on the extensions and strip out unneeded binaries etc.
Basically its a simple plan , keep it relative ! , keep all your configuration paths relative from where you launch the program ! , that's important , in the batch files shown later we launch from start.bat which is at the same level as our installation directory , we will be starting Apache from $usb:/pdrive/apache-2.0.50/bin , but our relative server root is still //pdrive//install_dir//apache-2.0.50 !
I am going to assume you have a local working copy of apache, MySQL and PHP , if not then you will need to download all of the above , get the PHP zip version not the installer
Create an installation directory on your USB flash drive , If you want to use the configuration files provided here , name it `pdrive` (or edit the config files)
Copy your PHP , MySQL & Apache directories into this installation directory , also create www and sess folders , and perhaps stick a simple phpinfo.php in the /www folder for testing later, also copy the php.ini to your installation directory.
You should now have ...
------------------------www/ *your document root add a phpinfo.php file to test*
------------------------sess/ *empty directory for session data*
You can view the sample php.ini config here & the httpd.conf here , also checkout the start.php and start.bat files, or download the zip here
OK , look at the sample config files I have provided , they are stripped down (e.g. comments removed) versions of the regular PHP,MySQL and Apache configuration files , the only parts we are really worried about in each are paths and directories. First try the configuration files as are (of course you will have to edit the paths to suit your apache and php versions ), they should just work as-is. If they do , then alter to suit your personal requirements, the only problem issues are mentioned below.
In general I like to use UNIX style forward slashes in any configuration files , not sure why but I do , normally this is not an issue and both php & apache are happy (on win32) with such if we are using absolute paths , however for relative paths I found the following conventions worked best..
[paths in php.ini]
extension_dir "/pdrive/php-5.0.3/ext" ;
[ & httpd.conf]
So 2 different conventions for the paths , other variations may well work , this is simply what works for me.
As it happens the my.cnf is ignored by mysql , & we also have to pass the important configuration changes via the command line.
httpd.conf .. should go in the usual place ( $usb:/pdrive/apache-2.0.50/conf/httpd.conf ).
my.cnf ? well we are passing the basic arguments via the command line so we can avoid using one.
Any port in a storm ?
Depending on the target system, its quite possible that they may already have a webserver (if not apache) running , less likely MySQL, but more and more desktop applications distribute MySQL these days so who knows .. anyway for testing purposes you need to run the servers on different ports than usual.
I have used 3307 for MySQL & 85 for Apache , these should not worry most firewalls other than an initial warning , if you do have any issues they are more than likely firewall related , I don't know what firewall you use , my NIS just asked me if it was OK to run these applications on the specified ports , I said yes , but then again that's the kind of guy I am.
If you need to change these ports you will need to alter my.cnf ([server] & [client] port), httpd.conf (listen & servername) & the php.ini (mysql default port) just search for 3307 & 85.
OK that's that , now we need to start them , we could open a command prompt and start apache & MySQL from there ... but then the above configurations will not work, that's because I wanted to start everything from a batch file .. or better still PHP :) , you may of course create an autorun facility so the servers startup when the USB is plugged in , more of that later.
To start everything I use a php script , and start that with a batch file
start.php (save as $usb:/pdrive/start.php )
start.bat (save as $usb:/start.bat )
echo "starting MySQL ....\n";
'start pdrive\\mysql\\bin\\mysqld-nt.exe --basedir=/pdrive/mysql --datadir=/pdrive/mysql/data --port=3307 --console --standalone'
echo "starting apache....\n";
echo 'opening localhost';
exec( 'start http://localhost:85');
/pdrive/php-5.0.3/php.exe -c /pdrive/php.ini -f /pdrive/start.php
ok . double clicking start.bat will start MySQL & then apache in new command windows , you can lose the MySQL window by removing --console from the command string , however that makes it very hard to then kill MySQL , you can ctrl-alt-delete , but if you have more than one instance of MySQL running then , due to the crappy task manager provided by windows , you wont know which one to kill (e.g. the one running on port 3307).
as noted above if you want to lose the command windows , the MySQL one can be removed by not running the --console switch , however for apache , all you can do to lose the console window is to install as a service , which you probably do not want to do for a USB AMP installation.