|

How to set up a CGI/Perl/MySQL web-development
environment under Windows 98
Windows 98 works well as a web-development environment. Included with Windows
98 is Microsoft's Personal Web Server, which can be used to serve your pages
stored locally. This way you don't have to upload your files to test them. Just
save them out and refresh using your browser of choice to see your changes.
Some installations of Windows 98 don't have PWS installed. If this is the case,
use Help in the Start Menu
and search for "PWS". Also, Personal
Web Server doesn't seem to support server-side includes, so I use Perl
to build the entire page.
Administering Personal Web Server
With PWS installed you should have a PWS icon in your systray
at the bottom-right of the screen. Double-click to bring up your Personal
Web Server Properties.
Under Windows 98, there should be four tabs labeled General,
Startup, Administration
and Services.
Under the General tab, set up your default
home page path. Then go the Administration
tab. Click the Administration button to bring up
the Web-based server administrator in a browser window. Under WWW
Administration there's a Directories tab.
The important directories to set are associated with <Home>
and /cgi-bin. For example, if you're using Dreamweaver,
most likely you should set C:\Sites\mysite as your
<Home> directory and C:\Sites\mysite\cgi-bin
as your /cgi-bin directory. Check that static pages
get served properly to your browser.
Installing Perl
Next, you need Perl. Go to www.activestate.com
and download and install the latest version of Perl. You'll need a couple additional
Perl modules to interface with MySQL. Use the Perl Package Manager (ppm)
that's included with ActiveState Perl to get them.
c:\perl\bin>ppm install Data-Dumper
c:\perl\bin>ppm install DBI
c:\perl\bin>ppm install DBD-mysql
Using ppm install didn't work for me due to a
bug in the release that I downloaded. If you encounter a problem installing
a module, there are zip versions of the modules
available on ActiveState's site.
You can use
c:\perl\bin>ppm query
to get a list of installed packages after installing the new ones. Verify that
you have Data-Dumper, DBI,
and DBD-mysql packages installed.
Now, get Perl working with Personal Web Server. Refer to this Microsoft
online technical article about modifying your registry.
Does Perl work as a CGI script through PWS?
Save this script to your /cgi-bin directory as
test.pl.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Wassup!</h1>\n";
In your browser, go to http://localhost/cgi-bin/test.pl
localhost in this case is the name of your computer.
Does it work?
Installing MySQL
Go to www.mysql.com and get the latest Windows
distribution, typically named mysqlwin-version.zip.
Unzip it and run the setup program to install MySQL into c:\mysql.
You can start the server using
c:\mysql\bin>mysqld-opt
The -opt means it's optimized for Pentium processors.
You can also use
c:\mysql\bin>winmysqladmin
The Windows administration program will install itself into your systray
and can automatically start MySQL every time you boot up.
MySQL has a database that it uses to keep track of users. In order to
allow access to a MySQL database from a CGI script you'll need to grant access.
Suppose you've created a database called db_mysite_com
and you want the user javier to have access.
c:\mysql\bin>mysql
mysql> grant all on db_mysite_com.*
mysql> to javier@localhost
mysql> identified by "javierspassword";
localhost in this case is not the name
of your computer, it's localhost.
Test out MySQL to make sure it works. Create a test database and create some
tables and insert some rows using the mysql client.
Connect to MySQL using Perl DBI.
use DBI;
my $dsn = 'DBI:mysql:db_mysite_com:localhost';
my $db_user_name = 'javier';
my $db_password = 'javierspassword';
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);
If you get a connection error, check that the MySQL server is running. If you're
using winmysqladmin then the street light icon
that it displays in your systray should have a
green light. If it has a red light, then right-click the icon and Start
Server.
For more information on using MySQL or Perl DBI, refer to the feature article
titled, "MySQL using Perl DBI".
|