Date: September 6, 2002
Update: January 14, 2004
From: NoClue I've recently been fooling around with PHP, a scripting language that is
designed to be embedded into HTML. Support for MySQL is built into PHP (other
databases can also be used, of course, but MySQL seems to be the easiest).
PHP will work with Win9x's Personal Web Server (PWS) and Apache, but I've only run it
on IIS, so I'll leave that bit to someone who uses them. The install on WinXP is similar.
To see some of the things that can be done using PHP and MySQL, check out the OpenDB Lending Project.
OpenDB makes it easy to create a 'Media Library' (DVD's, CD's, VHS, Divx's, etc.)
to help you keep track of your stuff. You can add other users, and OpenDB will help
you remember who you lent your stuff to (or borrowed from).
In the time-honored CompuClues tradition of posting things as a memory aid (for the
next time I have to install this) and, hopefully, to encourage others to try new things, I
submit this step-by-step instruction list. ![[Smile]](images/smile.gif)
Get the stuff:
PHP: www.php.net
On the 'Downloads' page, look under 'Windows Binaries' and get both the .exe file and the
.zip file. We will install from the .exe, but we'll grab the extensions folder from the
.zip. The docs.
MySQL: www.mysql.com
Get the .zip from the 'Downloads' page. The docs.
phpMyAdmin: www.phpmyadmin.net
A PHP-based front-end for MySQL. It makes managing MySQL much easier. Get the .zip. The docs.
OpenDB: opendb.sourceforge.net
Get the .zip and the 'Default2' theme (the default theme can be pretty hard to read).
Dana Text Editor: www.rimarts.co.jp/dana.htm
Shareware. Not absolutely necessary, but the .php files we'll be editing will be a lot
easier to read than with Notepad. Your call.
Install Internet Information Server (IIS):
If IIS isn't already installed on your Win2000 Pro or Server machine, you can
add it by going to the 'Add/Remove Programs' control panel applet (you'll need your OS
disc handy, of course). Click on the 'Add/Remove Windows Components'. Check off IIS and
click 'Next'.
IIS adds a new Inetpub folder on your boot drive. Inside the Inetpub
folder, you'll find a wwwroot folder. We'll be dealing with this folder later on.
IIS Answers
Install PHP:
Run the PHP .exe file that you downloaded. The installation is pretty straighforward.
It creates a folder called \php, sets up the extensions for your web server, and
associates itself with .php files (and the older .php3 and .phtml files if you choose).
After the install finishes, open the \php folder, and create a subfolder called 'ext'.
Unzip the php .zip file to a temporary directory, and copy the contents of the
'extensions' folder to your new \php\ext folder.
Open the \Winnt\php.ini file in your favorite editor. Change the line 'display_errors='
to 'Off' (if you have problems later, you can always turn it back on).
On the 'extension_dir=' line enter c:/php/ext (note the forward slashes).
remove the semicolon from:
;extension=php_gd.dll
;extension=php_zlib.dll
(Note: In newer versions of PHP, the zlib library is no longer loaded
from an extension, so don't be afraid if you can't find the reference to it
in your php.ini file. Also, the gd library has been replaced by the gd2
library...use that one instead. - NoClue)
register_globals is off by default, you can leave it that way for OpenDB, but some
scripts require it.
Save php.ini.
To test your PHP installation, create a file in your favorite text editor
that contains the following code:
<?php phpinfo(); ?>
Name the file phpinfo.php and save it in your Inetpub\wwwroot folder.
Open the file in your browser (http://localhost/phpinfo.php). If PHP is
working, you should see a page that contains lots of information about
your server.
You can also test PHP from the command line...probably a good idea if
you can't get phpinfo.php to load. At the command prompt type:
cd\php and hit Enter. Then type:
php -i and hit Enter.
If PHP is working, you should see a bunch of HTML output (text with brackets around it), which is the output of the phpinfo() function.
The default page for most PHP scripts is usually 'index.php'. I find it
easier if I change the default document in IIS (or any subfolder if I have a different default page in the root). You don't have to do this, but it saves me hassle (well...typing) later on. Open the IIS console by right-clicking 'My Computer' and choosing 'Manage'. When the console opens, click the plus sign next to 'Services and Applications', then the plus sign next to 'Internet Information Services'. Right-click on 'Default Web Site' and choose 'Properties'. Click the 'Documents' tab. 'Enable Default Document' should be checked, and there will be a few listings in the box below it...default.htm, default,asp, etc. Click the 'Add' button, type index.php, and click 'Ok'.
Move it to the top of the list by highlighting it and clicking the arrows to the left.
Like I said, that step isn't necessary, but you'll be able to type, for instance,
'http://localhost/phpmyadmin' in your browser, rather than 'http://localhost/phpmyadmin/index.php'.
Install MySQL:
Unzip to a temporary folder. Run the setup file. You don't have to install it to your
C: drive, but it's easier to do it that way. See the documentation if you want to install
it to a different drive.
After setup finishes, you need to install it as a service. At a command prompt, type in
the following commands (in italics):
C:\> cd mysql and hit 'Enter'
C:\mysql> cd bin and hit 'Enter'
C:\mysql\bin> mysqld-nt --install and hit 'Enter' (note the 2 dashes before
install).
You should see 'Service successfully installed' when it's finished.
Then type:
C:\mysql\bin> net start mysql and hit Enter
You should see 'The MySQL service is starting' followed by 'The MySQL
service has started successfully'.
(You could, if you prefer, start the service from the console.
Right-click on 'My Computer' and choose 'Manage'. In the left pane, open the
'Services and Applications' listing, and click on 'Services' In the right pane, click on
'MySQL' to highlight it and click the 'Start Service' arrow on the toolbar...or I guess you
could just reboot, and let the service start by itself).
Install phpMyAdmin:
Unzip the .zip file into a temporary folder. Create a new folder in \Inetpub\wwwroot
called phpmyadmin. Copy the unzipped files to this new folder.
All of phpMyAdmin's configuration options are controlled by the file
config.inc.php. You make your changes to it by adding (or editing) the part
of each line after the equals sign but before the semicolon...between
the two single quotes. The first thing you must do is set the PmaAbsoluteUri
parameter:
Open config.inc.php in your favorite editor. On the line that
reads:
$cfg['PmaAbsoluteUri'] = '';
...change it to:
$cfg['PmaAbsoluteUri'] = 'http://localhost/phpmyadmin/'; (don't delete the semicolon at the end).
Save
the file (don't close it yet, we're not quite finished with it).
Open your browser to http://localhost/phpmyadmin/index.php
Click on 'Privileges' (called 'Users' in older versions). You'll see two users named 'root'. One has '%' as its host, the other
has 'localhost'. Edit each one and add a password. Click 'Go'. Once the passwords have
been added, you'll need to reload MySQL, click 'Reload MySQL'.
You'll need to add your new password to config.inc.php file (look for the
line that says $cfg['Servers'][$i]['password'] =) and resave it before
phpmyadmin will connect again (you can close it now).
Once phpMyAdmin reconnects, create a new database called 'opendb'.
(BTW...you may want to create a desktop shortcut for phpMyAdmin, or add it to your
favorites/bookmarks).
Install OpenDB:
Unzip the .zip file into a temporary directory. In \Inetpub\wwwroot, create a new
folder called 'opendb'. Copy the extracted files into this new folder.
Unzip the 'Default2' .zip file into a temporary directory. In the
\Inetpub\wwwroot\opendb\theme folder, create a folder called 'Default2'. Copy the
extracted files into this new folder.
Open the \Inetpub\wwwroot\include\config.php file in your editor. Add the database user
(root) and password. Change the 'Site Administrator' from Jason Pell to your name, and add
your email address. Save the file.
Open your browser to http://localhost/opendb/patch.php
Choose 'New Install' (don't worry about the version number). Click the 'Execute
opendb.sql' button. Once the tables have been created, click on the 'login' link. Login as
test/test.
Once you've logged in, create a new user for yourself, giving yourself Admin privileges
(you'll also want to set the theme to 'default2'...trust me ). I'm not sure how to remove the
'test' user, so just edit the user, changing the privileges to 'guest' and the password,
if you wish. Log out, and log in again as yourself (again...a shortcut/favorite would not
go amiss
).
To be safe, it's a good idea to turn off the patch function in the config.php file
after you've finished the install.
OpenDB uses connections to IMDB and freedb to make entering your movies and CD's easy.
It also shows charts and graphs (under Statistics) that, while not overly interesting by
themselves, are a good example of what is possible using PHP.
There are a ton of PHP tutorials and scripts on the 'net. One place to start might be
the PHP section of HotScripts.com.
Enjoy.
PS--I realize the most unzippers can extract files directly into a folder
(\wwwroot\opendb for example), but some of these files have embedded directories that can
be a PITA. If
you do it the way I've described, and dig down into any extracted folders for the files,
it'll be less confusing.
Oh yeah...the preceding assumes that you realize the dangers of running a web server
(Nimda, etc.) and have some sort of firewall in place along with a good up-to-date virus
scanner.
If you don't understand these dangers, post a question in the 'Security' forum.
Oh yeah again...all the stuff in the preceding article is free. Except
Dana...and MySQL if you use it commercially.
(Note: This article assumes that you will be running all of this stuff on
a single machine. If you want to connect to it over your LAN, or over the
Internet, you'll need to replace 'localhost' in all the URLs and URIs
above with the Fully Qualified Domain Name (FQDN) of your machine. -
NoClue). |