faqts : Computers : Operating Systems : Microsoft : bilal

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

Microsoft: Windows:WAMP:USB: Microsoft:Windows: How to install Apache+PHP+MySql on USB stick? [LAMP]

Mar 26th, 2005 01:05
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 23 March 2005 - 10:00 am ----------------------

Microsoft: Windows:WAMP:USB: Microsoft:Windows: How to install 
Apache+PHP+MySql on USB stick? [LAMP]

---

Steps: Overview:

 1. -Install e.g. Apache, MySql, PHP as usual on your hard drive

 2. -Create the Apache, MySql, PHP directories on your USB stick

    1. Create your Apache directory on your USB stick

--- cut here: begin --------------------------------------------------

        MD h:\pdrive
        MD h:\pdrive\apache

--- cut here: end ----------------------------------------------------

    2. Create your MySql directory on your USB stick

--- cut here: begin --------------------------------------------------

        MD h:\pdrive
        MD h:\pdrive\mysql

--- cut here: end ----------------------------------------------------

    3. Create your PHP directory on your USB stick

--- cut here: begin --------------------------------------------------

        MD h:\pdrive
        MD h:\pdrive\php

--- cut here: end ----------------------------------------------------

 2. -Copy that whole directories to your USB stick

    1. -Use Microsoft Explorer

       1. Drag and drop the directories

    -- or --

    2. -On the command line type for example:

--- cut here: begin --------------------------------------------------

        xcopy <your Apache directory> <your USB Apache directory> /E

         e.g.

        xcopy "c:/program files/apache group" "h:\pdrive\apache" /E

--- cut here: end ----------------------------------------------------

---

--- cut here: begin --------------------------------------------------

        xcopy <your MySql directory> <your USB MySql directory> /E

        e.g.

        xcopy "c:/program files/MySql" "h:\pdrive\mysql" /E

--- cut here: end ----------------------------------------------------

---

--- cut here: begin --------------------------------------------------

        xcopy <your PHP directory> <your USB PHP directory> /E

        e.g.

        xcopy "c:\php" h:\pdrive\php /E

--- cut here: end ----------------------------------------------------

 3. -Adapt the configuration files for Apache, MySql, PHP
     (go through this configuration files and change only the entries
      as shown here to the conditions on your own USB stick)

     1. Apache configuration file (=httpd.conf)

--- cut here: begin --------------------------------------------------

# ---------------------------------------------------------------------
ServerRoot "/pdrive/apache/Apache2"
# ---------------------------------------------------------------------
LoadModule php5_module "\\pdrive\php\\php5apache2.dll"
addtype application/x-httpd-php .php .php4 .php5 .php3
PHPIniDir "\\pdrive\\php\\php.ini"
# ---------------------------------------------------------------------
ServerName test:80
# ---------------------------------------------------------------------
DocumentRoot "/pdrive/apache/Apache2/htdocs"
# ---------------------------------------------------------------------
<Directory "/pdrive/apache/Apache2/htdocs">
# ---------------------------------------------------------------------
Alias /icons/ "/pdrive/apache/Apache2/htdocs"
# ---------------------------------------------------------------------
<Directory "/pdrive/apache/Apache2/htdocs">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
# ---------------------------------------------------------------------
<Directory "/pdrive/apache/Apache2/manual">
# ---------------------------------------------------------------------
ScriptAlias /cgi-bin/ "/pdrive/apache/Apache2/htdocs"
# ---------------------------------------------------------------------
ScriptAlias /php/ "/pdrive/php/"
# ---------------------------------------------------------------------
AddType application/x-httpd-php .php
# ---------------------------------------------------------------------
Action application/x-httpd-php "/php-cgi.exe"
# ---------------------------------------------------------------------
<Directory "/pdrive/apache/Apache2/cgi-bin">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>
# ---------------------------------------------------------------------

--- cut here: end ----------------------------------------------------

     2. MySql configuration file (=my.ini)

--- cut here: begin --------------------------------------------------

# ---------------------------------------------------------------------
port=3306
# ---------------------------------------------------------------------
basedir=/pdrive/MySQL/MySQL_Server_4.1/
# ---------------------------------------------------------------------
datadir=/pdrive/MySQL/MySQL_Server_4.1/Data/
# ---------------------------------------------------------------------

--- cut here: end ----------------------------------------------------

     3. PHP configuration file (=php.ini)

--- cut here: begin --------------------------------------------------

# ---------------------------------------------------------------------
doc_root = "/pdrive/apache/Apache2/htdocs"
# ---------------------------------------------------------------------
extension_dir = "h:/pdrive/php/ext/"
# ---------------------------------------------------------------------
extension=php_mysql.dll
# ---------------------------------------------------------------------

--- cut here: end ----------------------------------------------------

 4. -Test if Apache is working

    1. -Stop any other webserver running

        1. Stop Microsoft Internet Information Server (IIS)

           1. On the command line type the command

               <your windows directory>\system32\iireset.exe /stop

               e.g.

               %WINDIR\system32\iireset.exe /stop

              or use the taskmanager to stop the process

               inetinfo.exe

    2. -Open your browser

       1. -Type the URL

          localhost

          1. This should show the index page of Apache

 5. -To run Apache + MySql + PHP

     1. Copy the file start.bat to the root of your USB stick

[file: start.bat]

--- cut here: begin --------------------------------------------------

@REM -----------------------------------------------
@REM call with the USB drive letter as a parameter
@REM
@REM ---
@REM
@REM e.g. to start this batch file
@REM      type on the MSDOS command line:
@REM
@REM  start h:\start.bat h:
@REM
@REM -----------------------------------------------
@REM change to the USB drive
%1
@REM -----------------------------------------------
@REM change to the root of the USB drive
cd \
@REM -----------------------------------------------
@REM change the driveletter 'h:' in the PHP configuration 
file 'php.ini'
@REM (change the driveletter to your specific USB stick driveletter 
(e.g. 'f:'),
@REM  or you will get a 'php_mysql.dll' not found)
@ECHO "change the driveletter 'h:' in 'php.ini' file to your current 
USB driveletter
@ECHO "(search with <CTRL><F> for the word 'extension_dir' in your 
php.ini file,
@ECHO "change the driveletter to the driveletter of your USB stick
@ECHO "then press <CTRL><S> to save your file
@ECHO.
notepad.exe \pdrive\php\php.ini
@ECHO.
@PAUSE press any key to continue (after you changed driveletter and 
saved your php.ini file)
@ECHO.
@REM -----------------------------------------------
@REM add the MySql path to the PATH (to find 'libmysql.dll')
@REM (otherwise you might have to copy the file 'libmysql.dll' to your 
local \windows directory)
@REM
@REM (you might have to change this path once for your specific USB 
stick directory)
PATH=%PATH%;\pdrive\mysql\mySQL_Server_4.1\bin
@REM -----------------------------------------------
@REM run the php program from the command line with your script as a 
parameter
\pdrive\php\php.exe -c \pdrive\php\php.ini -f \pdrive\start.php
@REM -----------------------------------------------

--- cut here: end ----------------------------------------------------

     2. Copy the file start.php to your 'pdrive' directory on your USB 
stick

[file: start.php]

--- cut here: begin --------------------------------------------------

<?php
// --------------------------------------------------------------------
echo "starting MySQL ....\n";
pclose( popen( 'start \\pdrive\\mysql\\MySQL_Server_4.1\\bin\mysqld-
nt.exe --defaults-file="/pdrive/mysql/MySQL_Server_4.1/my.ini" --
basedir="/pdrive/mysql/MySQL_Server_4.1/" --
datadir="/pdrive/mysql/MySQL_Server_4.1/data/" --standalone', 'r' ) );
// --------------------------------------------------------------------
echo "opening MySQL command line\n";
pclose( popen( 'start \\pdrive\\mysql\\MySQL_Server_4.1
\\bin\mysql.exe', 'r' ) );
// --------------------------------------------------------------------
echo "stopping Microsoft Internet Information server (IIS)....\n";
exec( GetEnv( 'WINDIR' ) . "\\system32\\iisreset.exe /stop" );
// --------------------------------------------------------------------
echo "starting Apache....\n";
flush();
pclose( popen( 'start \\pdrive\\apache\\Apache2
\\bin\\Apache.exe', 'r' ) );
flush();
sleep(5);
// --------------------------------------------------------------------
echo "opening localhost\n";
exec( 'start http://localhost');
// --------------------------------------------------------------------
?>

--- cut here: end ----------------------------------------------------

     3. You should now see the following directory structure on your
        USB stick

--- cut here: begin --------------------------------------------------

\
 pdrive
  apache
   Apache2
    bin
    conf
     httpd.conf
    ...
  mysql
   mySQL_Server_4.1
    my.ini
    ...
  php
   php.ini
   ...
  sess
  www
  start.php
 start.bat

--- cut here: end ----------------------------------------------------

---

        or this directory structure shown as a tree:

--- cut here: begin --------------------------------------------------
|
+--\
|  |
|  +--pdrive
|  |  |
|  |  +--apache
|  |  |  |
|  |  |  +--Apache2
|  |  |  |  |
|  |  |  |  +--bin
|  |  |  |  |
|  |  |  |  +--conf
|  |  |  |  |  |
|  |  |  |  |  +--httpd.conf
|  |  |  |  |
|  |  |  |  +--...
|  |  |
|  |  +--mysql
|  |  |  |
|  |  |  +--mySQL_Server_4.1
|  |  |  |  |
|  |  |  |  +--my.ini
|  |  |  |  |
|  |  |  |  +--...
|  |  |
|  |  +--php
|  |  |  |
|  |  |  +--php.ini
|  |  |  |
|  |  |  +--...
|  |  |
|  |  +--sess
|  |  |
|  |  +--www
|  |  |
|  |  +--start.php
|  |
|  +--start.bat

--- cut here: end ----------------------------------------------------

---
---

     4. You will currently have to change your driveletter to your 
current USB
        driveletter only at 1 position in the 'php.ini' file

        Currently the USB diskletter (e.g. 'h:\') is hardcoded in the
        configuration file for 'php.ini' on the USB stick.
        In all other configuration files (e.g. httpd.conf, my.ini
        the driveletter does not appear, as you change automatically to
        your USB drive via the start.bat file)

        Note:

        1. Print the text of the configuration files
           dynamically including the drive letter.

           It could become completely automated if you 'print' the
           content of your php.ini via e.g. 'ECHO' or 'print' and
           'echo' commands in a .bat batch script, or a .php PHP
           script.

        2. So once you know the driveletter for your USB stick,
           open the file php.ini on your USB stick (e.g. using notepad)
           and change there the driveletter from 'h:' to your current
           USB drive letter (e.g. 'f:').
           You will have to do this once for your USB stick,
           once you plug it in your computer, so its current
           driveletter becomes known to you.

           1. Search for the word 'extension_dir'
              in your php.ini

               before you editing it:

--- cut here: begin --------------------------------------------------

           extension_dir = "<your USB driveletter>/pdrive/php/ext/"

--- cut here: end ----------------------------------------------------

            e.g.

--- cut here: begin --------------------------------------------------

            extension_dir = "h:/pdrive/php/ext/"

--- cut here: end ----------------------------------------------------

           after you editing it, and you know your driveletter,
           e.g. 'f:', it becomes thus

--- cut here: begin --------------------------------------------------

            extension_dir = "f:/pdrive/php/ext/"

--- cut here: end ----------------------------------------------------

        2. save your php.ini file

     5. Finally run the 'start.bat' file in the root of your USB stick
        and supply the driveletter of your USB stick as a parameter

         e.g. If your USB stick driveletter is 'f:',
              then type on the MSDOS command:

--- cut here: begin --------------------------------------------------

               f:\start.bat f:

--- cut here: end ----------------------------------------------------

         e.g. If your USB stick driveletter is 'g:',
              then type on the MSDOS command:

--- cut here: begin --------------------------------------------------

               g:\start.bat g:

--- cut here: end ----------------------------------------------------

         in general

--- cut here: begin --------------------------------------------------

               <your USB driveletter>\start.bat <your USB driveletter>

--- cut here: end ----------------------------------------------------

---
---

Total USB disk space needed.

The total filesize of this pdrive directory on my USB stick
is about 160 megabytes, using my original installations
of Apache, MySql, PHP.

---
---

Tested successfully on

Microsoft Windows XP Professional, running

Apache v2.0

PHP v5.0.3

MySql 4.1

on a 1 gigabyte USB stick

---
---

Troubleshooting:

1. Make sure the libmysql.dll is in your environment PATH,
   otherwise copy it once to your c:\windows directory on the
   computer you are working with the USB stick

2. Do not use the '--console' parameter for mysqld-nt.exe, or else you
   will get the 'shell64.dll' error

3. 'HTTP 404 - File not found' error when typing the URL of a .php file
   in the browser:

   1. e.g. type in your browser:

       localhost\test.php

      (with this file 'test.php' located in the htdocs directory on the
      USB stick, and other e.g. .htm files in this directory did not
      show this error, so it should have something to do with the file
      extension, here 'php') it showed in the browser the error '404
      page not found'

      1. Now typing 'localhost' only worked also fine, so the Apache
         web server was up and running.

         1. If I close the MSDOS box running Apache .exe, and
            then trying to type 'localhost' gives then suddenly
            'Page not found', so it is that web server that is
            running (and not another web server).

      2. Typing the full path of the php file

          h:\pdrive\apache-2.0.50\Apache2\htdocs\test.php

         gives the reaction that it asks via a message box which
         program to use to open this file.
         This is a different reaction then typing 'localhost\test.php',
         thus the web server must be involved (instead of the web
         browser).

      3. So it must have something to do with the php settings in the
         PHP configuration file php.ini and or the Apache
         configuration file.

      4. There was only 1 php.ini and 1 httpd.conf file involved on
         my computer, so looking there was the most probable.

      5. I solved it by using the module installation of PHP instead
         and or the php-cgi.exe

---
---

Internet: see also:

---

[Internet: source: http://www.google.com search for 'install Apache 
PHP MySql USB': http://www.firepages.com.au/php_usb.htm]

---

Operating system: Microsoft Windows: WAMP: Link: Overview: Can you 
give an overview of links? [LAMP]
http://www.faqts.com/knowledge_base/view.phtml/aid/33803/fid/772

----------------------------------------------------------------------