Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Windows - running Apache and MySQL from a CD

Q - I'm writing a web based application (using PHP and MySQL) and I've just been told that I also need to produce a stand alone demo version to run on PCs running windows. What shall I do?

A - Configure an Apache server, PHP and MySQL to run from a CD, using port numbers that aren't normally used. Add a batch file to install the few directories that need to be writable on the user's PC, and to kick off the services / daemons. Your demo version will then be useable in just the same way as the web based application - it will even be accessible on your intranet if the demo PC is connected! Since all the components of the system are Open Source, you shouldn't have licensing issues if you're giving away your demo version - but it might be as well to check with the MySQL folks in particular if you're going to be selling it to make money - their general motto is "If you're distributing it for free, we're free. If you're charging, then we'll charge you".

A grand theory, but does it work in practice? Yes, we've done it!

In detail:

PREPARING FOR THE INSTALLATION

1. Create a folder under the top level of your C: drive (in our example, we've called it c:\dcserver)

2. Download the distributions that you want to install on your server - we've put ours into a subdirectory of dcserver to that the full originals will be distributed onwards with the CD, making open source license adherence easier and ensuring that we have all the original tools available for tailoring later.
     apache_1.3.31-win32-x86-no_src.exe
     mysql-4.0.21-win.zip
     php-4.3.9-Win32.zip

INSTALLING APACHE AND PHP

3. Install the web server to a subdirectory of dcserver (we've chosen to call ours Apache)

4. Install the PHP distribution to a subdirectory of dcserver (we've called ours PHP)

5. Copy the PHP .dll files and the php.ini file from the php directory to the apache directory as described in the PHP installation instructions

6. Create a subdirectory for read/write information testing on the c: drive - we've called ours c:\dcdata

7. Modify the Apache configuration file, removing drive-specific references (since you don't know what drive letter will be used when you run the CD) and pointing error log and other output areas at the c:\dcdata area. Here's a log of the changes we made for this purpose using the above releases of the software. Other mods are made here too - we've also changed the server from port 80 to port 8000 to avoid conflict with any other web server running on the host system, and we've added in the extra stuff to call up the PHP.

61c61
< ServerRoot "C:/dcserver/apache/Apache"
---
> ServerRoot "/dcserver/apache/Apache"
67c67
< PidFile logs/httpd.pid
---
> PidFile c:/dcdata/httpd.pid
75c75
< ScoreBoardFile logs/apache_runtime_status
---
> ScoreBoardFile c:/dcdata/apache_runtime_status
150a151
> Listen 8000
268c269
< Port 80
---
> Port 8000
301c302
< DocumentRoot "C:/dcserver/apache/Apache/htdocs"
---
> DocumentRoot "/dcserver/apache/Apache/htdocs"
326c327
< <Directory "C:/dcserver/apache/Apache/htdocs">
---
> <Directory "/dcserver/apache/Apache/htdocs">
360c361
< UserDir "C:/dcserver/apache/Apache/users/"
---
> UserDir "/dcserver/apache/Apache/users/"
480c481
< ErrorLog logs/error.log
---
> ErrorLog c:/dcdata/httpderror.log
505c506
< CustomLog logs/access.log common
---
> # CustomLog logs/access.log common
580c581
< Alias /icons/ "C:/dcserver/apache/Apache/icons/"
---
> Alias /icons/ "/dcserver/apache/Apache/icons/"
582c583
< <Directory "C:/dcserver/apache/Apache/icons">
---
> <Directory "/dcserver/apache/Apache/icons">
593c594
< Alias /manual/ "C:/dcserver/apache/Apache/htdocs/manual/"
---
> Alias /manual/ "/dcserver/apache/Apache/htdocs/manual/"
595c596
< <Directory "C:/dcserver/apache/Apache/htdocs/manual">
---
> <Directory "/dcserver/apache/Apache/htdocs/manual">
610c611
< ScriptAlias /cgi-bin/ "C:/dcserver/apache/Apache/cgi-bin/"
---
> ScriptAlias /cgi-bin/ "/dcserver/apache/Apache/cgi-bin/"
616c617
< <Directory "C:/dcserver/apache/Apache/cgi-bin">
---
> <Directory "/dcserver/apache/Apache/cgi-bin">
826a828,834
>
> ####################### Extra Stuff!!
>
> AddType application/x-httpd-php .php .php4
> LoadModule php4_module "/dcserver/apache/Apache/bin/php4apache.dll"
> SetEnv PHPRC /dcserver/apache/Apache/bin
>

8. Start the test server by running the apache.exe file that's at the top of the Apache tree; you should get a message that Apache and PHP have started

TESTING APACHE AND PHP

9. Point your browser at
 http://localhost:8000/
and you should see a "your Apache server has been successfully installed" page.

10. place the following in a file called first.html in the htdocs directory
 <html>
 <head><title>Stand Alone Apache Test</title></head>
 <body><h1>Test</h1>Server operational</body>
 </html>
and point your browser at
 http://localhost:8000/first.html

11. place the following in a file called second.php in the htdocs directory
 <h1>Stand Alone CD Server verification</h1>
 <?php phpinfo(); ?>
and point your browser at
 http://localhost:8000/second.php

INSTALLING AND TESTING MYSQL AND ITS LINK TO APACHE AND PHP

12. Unpack and install MySQL in a subdirectory of c:\dcserver (i.e. run the setup.exe script)

13. Start the MySQL server on port 3307 using
 mysql\bin\mysqld --port=3307 --basedir=/dcserver/mysql --datadir=/dcserver/mysql/data/

14. log in to MySQL and set up a test user account - let's call it user "trainee" with password "abc123". Also at this stage you should set the root password for the SQL server.

15. Create a test table in mysql - for example use the mysql client program to
 use test;
 create table example (id int primary key not numm auto_increment,
   info text);
 insert into example (info) values ("The sky is blue");
 insert into example (info) values ("The grass is green");

16. Test the MySQL in association with the web server and PHP by creating the following file in the htdocs area of apache - called third.php:
 <h1>MySQL test</h1>
 <?php
 mysql_connect("localhost:3307","trainee","abc123") ;
 mysql_select_db("test");
 $rid = mysql_query("select * from example");
 while ($igot = mysql_fetch_assoc($rid)) {
         echo $igot[info];
         echo "<br>";
        }
  ?>
  <hr>
and point your browser at:
 http://localhost:8000/third.php

At this point you should see a complete PHP page showing the contents of the SQL database. However, the database is running from the dcserver directory which is read/write and this won't work if you try to cut it onto a CD and run from the CD.

The following stages show you how to add batch files onto your CD to copy vital files into the dcdata area when you run from CD on a target machine. You should try these out for testing at this stage, but you'll need to come back and add your application itself into the htdocs directory and into your SQL database and cut production CDs later.

ADDING THE BATCH FILES TO START THE SERVERS AND CUTTING THE CD

17. Add a file called appstart.html to the htdocs directory to represent the portal to your application
 <html>
 <head><title>Welcome to the Super Application (CD version)</title></head>
 <body>
 This is where the fun stuff goes<br>
 <hr>
 For support staff<br>
 <a href=second.php>PHP test</a><br>
 <a href=third.php>PHP and SQL test</a><br>
 If these tests fail, you have server problems<br>
 </body>
 </html>


18. Add the file README.html into the \dcserver directory as follows:
 <pre>
 This is the readme file for starting your CD based application....

 To run the web server and Digital Class application from this folder:

 a) Doubleclick on startsql.bat
 b) Doubleclick on startweb.bat
 c) Point a browser at
         http://localhost:8000/appstart.html


 Failure to follow these instructions may lead to the software failing
 to work.

 </pre>

 Link <a href=http://localhost:8000/appstart.html>HERE!</a> to Digital class

19. Add a file startsql.bat to the \dcserver directory as follows:
 echo "Starting SQL server. Please ensure web server also started"
 if not exist c:\dcdata mkdir c:\dcdata
 if not exist c:\dcdata\ibdata1 xcopy \dcserver\mysql\data\*.* c:\dcdata /Q/S
 mysql\bin\mysqld --port=3307 --basedir=/dcserver/mysql --datadir=c:/dcdata --read-only

20. Add a file startweb.sql to the \dcserver directory as follows:
 echo off
 echo "Starting web server. Please ensure SQL server also started"
 if not exist c:\dcdata mkdir c:\dcdata
 echo .
 echo .
 echo .
 echo After Web server start message, please ensure SQL server is started
 echo .
 echo .
 echo .
 apache\apache\apache

21. Ensure that the web and SQL servers are shut down (a reboot is not a bad idea!)

22. Cut a test CD.

RUNNING YOUR CD BASED APPLICATION FROM THE TEST CD

a. Insert the CD into the CD drive on the target computer; a window showing its contents will pop up.

b. Double click on the "startsql" icon

c. Double click on the "startweb" icon

d. Double click on the README.html icon and a browser window will start up. You can follow the links from that page to test your installation.

ACCESSING THE TEST SERVER FROM ANOTHER MACHINE ON YOUR NETWORK

a. Establish the name or IP address of the machine on which the CD is running.

b. Point a browser on your second test machine at
 http://192.168.200.147:8000/appstart.html
(replace the IP address in this example as appropriate, but leave the 8000 port number)

Some notes:

i) This is an example setup that you're welcome to use as guidance
- it works for us but you may find different circumstance and you
may wish to modify the procedure. No responsibility can be taken by the author of these notes for any errors or shortcomings, nor the consequences thereof.

ii) The data in the SQL database is left on the hard disc from one run to the next and the sample batch files do NOT overwrite it. You may wish to modify this behaviour for security reasons, or if you want a fresh new start each time.

iii) These notes are written by Graham Ellis of Well House Consultants (graham@wellho.net) and are subject to the copyright statement (c) 2004 on our web site. Please visit our web site (http://www.wellho.net) for details of our training courses which include PHP Programming. MySQL, and Apache configuration and deployment


See also Sourcing, configuring and installing Apache httpd

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Web Application Deployment - Apache httpd - Sourcing, Installation, Testing
  [3426] Automed web site testing scripted in Ruby using watir-webdriver - (2011-09-09)
  [2520] Global and Enable - two misused words! - (2009-11-30)
  [2184] Choosing the right version of Java and Tomcat - (2009-05-16)
  [2096] Where is my new Apache httpd installed - (2009-03-22)
  [2080] Using ApacheBench and jconsole to test and monitor Tomcat - (2009-03-14)
  [1945] Summary - Apache httpd build on Linux - (2008-12-14)
  [1768] What is built in to this httpd and PHP? - (2008-08-23)
  [1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
  [1707] Configuring Apache httpd - (2008-07-12)
  [1455] Connecting to MySQL 5 from PHP on Mac OSX Leopard - (2007-12-03)
  [1449] Upgrade Mac OSX to Leopard, Web Server Apache httpd config lost - (2007-11-29)
  [1292] DHCP automatic IP address v Static IP - (2007-08-06)
  [1095] Apache httpd , browser, MySQL and MySQL client downloads - (2007-02-28)
  [982] Notes from the white board - (2006-12-14)
  [907] Browser -> httpd -> Tomcat -> MySQL. Restarting. - (2006-10-28)
  [660] Stopping and restarting Apache httpd cleanly - (2006-03-29)
  [550] 2006 - Making business a pleasure - (2006-01-01)
  [526] Apache httpd - serving web documents from different directories - (2005-12-12)
  [523] Apache httpd release 2.2 - (2005-12-10)

Web Application Deployment - Further httpd Configuration
  [4307] Identifying and clearing denial of service attacks on your Apache server - (2014-09-27)
  [4001] Helping search engines with appropriate 400 error codes - (2013-02-11)
  [3955] Building up from a small PHP setup to an enterprise one - (2012-12-16)
  [3862] Forwarding a whole domain, except for a few directories - Apache http server - (2012-09-17)
  [3635] Parse error: parse error, unexpected T_STRING on brand new web site - why? - (2012-03-03)
  [3449] Apache Internal Dummy Connection - what is it and what should I do with it? - (2011-09-19)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
  [2900] Redirecting a page - silent, temporary or permanent? - (2010-08-03)
  [2478] How did I do THAT? - (2009-10-26)
  [2272] Monitoring and loading tools for testing Apache Tomcat - (2009-07-07)
  [2060] Database connection Pooling, SSL, and command line deployment - httpd and Tomcat - (2009-03-01)
  [1974] Moving a directory on your web site - (2009-01-03)
  [1955] How to avoid duplicating web page maintainance - (2008-12-20)
  [1954] mod_rewrite for newcomers - (2008-12-20)
  [1939] mod_proxy_ajp and mod_proxy_balancer examples - (2008-12-13)
  [1778] Pointing all the web pages in a directory at a database - (2008-08-30)
  [1767] mod_proxy and mod_proxy_ajp - httpd - (2008-08-22)
  [1762] WEB-INF (Tomcat) and .htaccess (httpd) - (2008-08-20)
  [1707] Configuring Apache httpd - (2008-07-12)
  [1636] What to do if the Home Page is missing - (2008-05-08)
  [1619] User and Group settings for Apache httpd web server - (2008-04-22)
  [1566] Strange behaviour of web directory requests without a trailing slash - (2008-03-06)
  [1564] Default file (MiMe types) for Apache httpd and Apache Tomcat - (2008-03-04)
  [1554] Online hotel reservations - Melksham, Wiltshire (near Bath) - (2008-02-24)
  [1551] Which modules are loaded in my Apache httpd - (2008-02-23)
  [1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
  [1377] Load Balancing with Apache mod_jk (httpd/Tomcat) - (2007-10-02)
  [1355] .php or .html extension? Morally Static Pages - (2007-09-17)
  [1351] Compressing web pages sent out from server. Is it worth it? - (2007-09-14)
  [1207] Simple but effective use of mod_rewrite (Apache httpd) - (2007-05-27)
  [1121] Sharing the load with Apache httpd and perhaps Tomcat - (2007-03-29)
  [1080] httpd.conf or .htaccess? - (2007-02-14)
  [1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
  [934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
  [853] To list a directory under httpd on a web server, or not? - (2006-09-02)
  [755] Using different URLs to navigate around a single script - (2006-06-11)
  [662] An unhelpful error message from Apache httpd - (2006-03-30)
  [649] Denial of Service ''attack'' - (2006-03-17)
  [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
  [550] 2006 - Making business a pleasure - (2006-01-01)
  [526] Apache httpd - serving web documents from different directories - (2005-12-12)
  [466] Separating 'per instance' data from binaries and web sites - (2005-10-16)
  [345] Spotting a denial of service attack - (2005-06-12)

Sourcing, Running and Configuring MySQL
  [2458] Cant connect to local MySQL server through socket /tmp/mysql.sock - (2009-10-17)
  [2445] Securing MySQL on a production server - (2009-10-09)
  [2444] Potted MySQL installation - (2009-10-09)
  [2426] Which version of MySQL am I running? - (2009-09-26)
  [2209] Monitoring and Tuning your MySQL installation - (2009-05-31)
  [2085] MySQL - licensing issues, even with using the name - (2009-03-16)
  [1935] Summary of MySQL installation on a Linux system - (2008-12-11)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
  [1689] Some sideways thoughts on the news - (2008-06-27)
  [1131] MySQL - Password security (authentication protocol) - (2007-04-02)
  [1123] mysqldump and mysqlrestore - (2007-03-30)
  [1095] Apache httpd , browser, MySQL and MySQL client downloads - (2007-02-28)
  [907] Browser -> httpd -> Tomcat -> MySQL. Restarting. - (2006-10-28)
  [591] Key facts - SQL and MySQL - (2006-02-04)
  [535] MySQL permissions and privileges - (2005-12-20)
  [515] MySQL - an FAQ - (2005-12-03)
  [489] Which MySQL server am I using? - (2005-11-07)
  [334] Symbolic links and hard links - (2005-06-02)
  [192] Current MySQL and PHP paths and upgrades - (2005-01-28)

resource index - Deployment
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/general- ... -a-cd.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard