David's Tips

Sometimes the simpliest things take forever, particularly when it comes to computers! I frequently have to install software, however, I always forget exactly what I needed to do and then, when I have to redo it, I invariably have to start from scratch again! This page is to remind me how to do various bits and pieces. No guarentees, but it may help you too. Let me know if you do find it useful or have any other tidbits to offer.


Windows 98 tips...

Call me slow, but I only just came across the new improved "System Information" program located in Start|Programs|Accessories|SystemTools.   This program not only tells you all about your computer's installation, it allows you to check and change lots of bits and pieces too without any hassle. Take a look at the "Tools" menu to find options for checking the Registry, DirectX, the file system and system configuration. This latter option allows you to modify win.ini, config.sys, autoexec.bat & programs which are automatically run at startup (useful!)

Need to switch keyboard languages in an MSDOS window?
    Hit Ctrl-Alt-F1  Simple and obvious, eh?


Installing PHP4 with Apache under Windows98

Download the Win32 version of PHP from www.php.net or a mirror e.g. tr.php.net

Unzip into c:\php4

Copy php4ts.dll to the c:\windows\system directory

Copy php.ini-optimized (or php.ini-dist if you want compatibilty with php3) and rename to php.ini (note will probably need to edit the extensions-dir to refer to c:\php4 so that modules such as imap and mysql will work.)

Copy php.ini to c:\windows

Make the following edits to the Apache httpd.conf file (in Apache conf directory!) Note: the line with php3 is not strictly needed, but allows older scripts, such as phpMyAdmin, to work without renaming!

ScriptAlias /php/ "c:\php4\"
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php .php3
Action application/x-httpd-php /php/php.exe

Restart the Apache server and (all being well) your PHP scripts should now work.

To test, create a file, mytest.php, containing the following

<?
  echo "Hello World\n";
?>

and save it in the document root of your web server (by default htdocs for Apache.)

Point your web browser to it and pray! You should also be able to run this file from an MSDOS window. Change to the directory containing it and type "c:\php4\php.exe mytest.php"

Note: Using sessions require that you change the session.save_path in php.ini to \windows\temp (or  some other directory that actually exists. The default /tmp usually doesn't exist on windows machines and hence trying to use sessions fails! I wonder why the default php.ini for windows installation isn't set up correctly?)


 

Installing Perl on Windows98

Download ActiveState perl from www.activestate.com (I used build 517 which is perl 5.004, but 522 is there now and the latest is for Perl 5.6) Simply double-click & accept everything! Note: all perl doc is availible in the Perl directory! 

I have a local copy of a simple Perl tutorial to get you started.

Note: The install program automatically adds Perl to your path and incorporates it into standard Microsoft webservers (IIS & PWS.) To make it available for cgi use on other servers, such as Apache, further work is needed!


 

Setup database access from Perl on Windows98
(eg. MSAccess & mysql)

Install your database and create the desired tables, etc.

Install perl then from dos prompt run the perl package manager, ppm

"info" shows what modules are currently installed (you need dbi -general database interface- plus a dbd -driver- for your particular database)

"install dbd-mysql" and/or "install dbd-odbc" (auto downloads and installs inc dbi too.)

You can run "dbish" (dbi shell) to test the setup. It lists available drivers & databases! Neat, why isn't it documented?

Simply change driver type -"dbi:mysql:thedb" or "dbi:ODBC:thedb"- to switch db's. See my example progs below & ones in Perl doc (in modules|site|dbi)

#!c:\Perl\bin\perl.exe
# test db selects from mysql server and MSAccess!
# David, August 2000
use DBI;

$dbName = "dbi:mysql:thedb";
#$dbName = "dbi:ODBC:thedb";
$dbUserName = "";
$dbPassword = "";

#$sql = "select * from Customers";
$sql = "select * from Customers where FirstName='David'";

$dbh = DBI->connect($dbName, $dbUserName, $dbPassword) || die $DBI::errstr;
$sth = $dbh->prepare($sql) || die $DBI::errstr;
$sth->execute() || die $DBI::errstr;

#while (@row = $sth->fetchrow_array()) {
#	print "$row[0], $row[1], $row[2], $row[3]\n\n";
#}

$nrows = 0;
while ($row = $sth->fetchrow_hashref()) {
print "$row->{email}, $row->{LastName}, $row->{FirstName}\n\n";
$nrows++;
}

print "Number of rows = $nrows\n";

$dbh->disconnect();

#!c:\Perl\bin\perl.exe
# tests update/insert/delete using mysql server and MSAccess!
# David, August 2000
use DBI;	# database independent db access!

$dbName = "dbi:mysql:thedb";
#$dbName = "dbi:ODBC:thedb";
#$dbName = "dbi:mysql:thedb;host=139.179.x.x";
#    Remote db access is not possible from MSAccess, only mysql.
#    Any of these forms seems to work too, but must have access rights to db!
#    #bilkent.edu.tr"; #davidsmachine"; #139.179.x.x";
$dbUserName = "";
$dbPassword = "";

$sqla = "INSERT INTO Customers ( FirstName, LastName, email) VALUES ('a', 'b', 'c')";
$sqlb = "UPDATE Customers SET FirstName='x' WHERE FirstName='a'";
$sqlc = "DELETE FROM Customers WHERE FirstName='x'";

$dbh = DBI->connect($dbName, $dbUserName, $dbPassword) || die DBI::errstr;

#### the crude way... ####
$dataObject = $dbh->do($sqla);

#### the fancy way... ####
#$sqla = "INSERT INTO Customers ( FirstName, LastName, email) VALUES (?, 'b', ?)";
#$dataObject = $dbh->prepare( $sqla);
#$dataObject->execute( "Derya", "derya\@cs.bilkent.edu.tr") || die $dataObject->errstr;

print "Content-Type: text\/html\n\n";
print "<html><body>\n<p>done.</p>\n</body></html>\n";
$dbh->disconnect();

 

Using MSAccess via ODBC

Install MSAccess from CD as any other Windows application.

Create a database and populate it!

To make it available via ODBC, open the control panel (Start|Settings|Control Panel)

Double click the "ODBC (32 bit)" icon.

Select the "System DSN" tab on the dialog that appears, then click the "Add" button. Select the appropriate type from the list (e.g. "MSAccess") and click "Finish".

Type the (logical) name you want to use for your database (e.g. mydatabase) in the "Data Source Name" area and add a brief description to remind you what's in it! Click "Select" and navigate to your actual (physical database), select it and then click "OK" as necessary.

 


PhpMyAdmin

This php code allows you to easily manage the mysql server via the web. Without it you have to use the mysql command line client on the local machine, which is a real pain!

Download latest version from http://www.phpwizard.net/projects/phpMyAdmin/index.html

Extract files to a directory reachable from the web.

Point browser to http://yourmachine/phpmyadmin/index.php3 and (assuming the webserver, php and mysql are all running nicely) you should be in business!

Note: phpMyAdmin requires magic_quotes_gpc = On; {default may be Off for php4} and register_globals = On { again php4 default maybe Off} You also need the webserver to execute scripts with php3 extensions (not just the default php, see installing php on Apache.) Finally, don't forget to check the mysql access privileges to make sure all is secure!

 


Installing Tomcat on Windows 98

This is the latest JavaServerPages 1.1 & Java Servlet 2.2 engine. It can run either standalone (usually on port 8080) or via Apache (on port 8007.) Being Java it runs everywhere (if you can figure out how to set it up.) Download from The Jakarta Project Subprojects - Tomcat and check the documentation at Tomcat User's Guide.

Under Windows 98, you have to make sure your path refers to your java/bin directory & the environment variable TOMCAT_HOME is set. Add "set TOMCAT_HOME=C:\tomcat" to your autoexec.bat file. If you are not going to use tomcat from Apache, but want Apache to continue to run JServ (the older servlet engine) then comment out the connection to port 8007 in server.xml so there is no conflict. If you are going to use tomcat exclusively from Apache, then comment out the other, port 8080, connection.

Having done this, Tomcat basically runs straight "out-of-the-box. You can check the installation by pointing a browser to http://theserverurl:8080 and the examples should run fine. You can add your own JSP's and servlets into the examples directory.

Unfortunately, you will probably want to do a few changes to that setup (to separate user areas for instance) and that is where your (my) difficulties start. The configuration is very complicated and not particularly well documented (at least I couldn't see/understand it!) So, a few tips... Check  JKL's Tomcat 3.1 Beta 1 UNIX FAQ since the setup is basically the same and this shows the directory structure with example urls (see below too), & OOP-Reserch Setting Tomcat3.1 with Apache - Tomcat and JServ which explains the logic behind the Apache/Tomcat connection.

While there is a /admin page which allows you to see and add contexts, it doesn't seem to save them (at least if you ^C to stop the server which is necessary on Win98 since shutdown don't seem to work!), so to add contexts properly, edit server.xml For example, the following

<Context path="/myjsp" docBase="c:/users/david/jsp" 
 debug="0" reloadable="true" />

adds a context called "myjsp" which maps to files in "c:/users/david/jsp" Assume that that directory has  files "welcome.html" and "snoop.jsp", plus a directory "web-inf" containing "web.xml" (copy the default one from "tomcat\conf") and a directory "classes" containing the servlets themselves, eg. SnoopServlet.class & HelloWorld.class. You should now be able to access these files as http://theserverurl:8080/myjsp/welcome.html & http://theserverurl:8080/myjsp/snoop.jsp, while the servlets need http://theserverurl:8080/myjsp/servlet/SnoopServlet The mapping to "servlet" is set up in the "tomcat/conf/web.xml" file. Presumably the section,

<servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

As far as I can see the "web-inf" directory name is fixed somewhere else. Note that the mapping to jsp pages immediately follows the above mapping (jsp -> *.jsp). Neat! Now, anyone tell me how to map all user directories as in Apache?

Note: Since the servlet directory is below the normal html/jsp one, moving this to a normal webserver makes them visible. To stop this you need to set up Apache to deny access to these subdirectories (see previous links.) Alternatively, you need to change the directory structure and map the servlets elsewhere somehow (this is left as an exercise for the reader!)

... more coming...??

 


Note: These scripting/servlet things are probably very unsafe on Windows 98 if users are allowed to upload whatever they wish, since they can directly access the entire file system. Linux & WinNT/2000 are presumably a little better since the webserver can be restricted to certain files, but even so... For a really secure system you must check the code!!