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

3 thoughts on “Windows – running Apache and MySQL from a CD

  1. moch. iqbal 11 September 2007 pukul 12:48 pm

    wow, your english is great….hehehe

  2. eksa 23 Agustus 2008 pukul 8:56 pm

    hehe..itu sih cuman copy paste aja bro…

  3. sandrar 10 September 2009 pukul 9:55 pm

    Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: