The Dysmey Post > Projects & Stuff > Personal Web Services

Personal Web Services

Introduction

I do a lot of my own Web work as a hobby. It is said that a hobby is a habit that costs money, but the tools I use for my Web work do not cost a thing. These tools fall under the acronym LAMP: Linux, Apache, MySQL and PHP. I have worked with Linux, mostly Red Hat and Fedora, but haven't used it lately because I can't afford the space that another computer would take up in my room. (I've been waiting — for years! — for nano-ITX motherboards to come out for just such a purpose.) For that reason I had to substitute Windows XP for Linux: It works just as well for what I need.

There are annoying limits on what I can do under Windows. As the most common of operating systems, Windows is a magnet for viruses, worms and other forms of crackery. That is why I must use firewall (ZoneAlarm), anti-virus (Symantec), and anti-spyware (AdAware) software. These in turn limit what I can use, as I will reveal.

Apache Web Server

If I had Windows XP Professional, then I would have the Microsoft Web server IIS. But I have only XP Home, which does not have a Web server of its own. (Personal Web Server, which shipped with Windows 9x, is no longer available.) This leaves me with no choice but to get the Apache Web server, software from the academic team that created Netscape. That's okay, though, because Apache is the most widely used Web server and is superior to IIS.

Apache exists in two versions. Version one continues to be available because the majority of sites use it. Version two, a complete redesign, is the latest and most favored. However, version two for Windows clashes with personal firewalls like ZoneAlarm and McAfee Guardian. Therefore I have no choice but to install version one.

That was in the early 2000's, when version two first came out. In 2005 the Apache Foundation released version 2.2, which was able to at least work with ZoneAlarm. This would make Apache 2.2 ideal once PHP 5.2 (which can be used with Apache 2.2) becomes available.

  1. Launch the Apache installer for Windows, currently apache_1.3.34-win32-x86-src.msi.
  2. License Agreement. Press "I accept …" to accept the legal boilerplate (you're okay if you use Apache for private use) and press Next.
  3. Read This First. This tells you, among other things, that you do NOT want to run Apache on Win9x or WinME as an Internet server. You can run it on Windows 2000 or Windows 2003 Server with the appropriate security settings, but there is no guarantee against vulnerability on a Windows server as there is on a Unix/Linux server. The Apache folks encourage Windows users to move to version two, but until the firewall issue is resolved, that is not going to happen.
  4. Server Information. The Web server is just for you alone, so the Network Domain and Server Name is localhost. The administrator address is admin@localhost. Install the Apache server to "Run as a service for All Users" (port 80). You can change the port setting later. The other choice is very messy, so don't use it.
  5. Setup Type. If you don't want Apache source code, you need to chose Custom, press Next, and in the next box, …
  6. Custom Setup. Choose the Apache Source Code item and turn it off. You can also turn off the Documentation, but you might to read it to learn how the server works. I don't know why, but the setup installs Apache to C:\Program Files\Apache Group\Apache\ instead of C:\Program Files\Apache\. I just press the Change button and change the folder path to the latter.
  7. Ready to Install…. Press the Install button and let's go!
  8. The Installation Wizard Completed box tells you that the server is up and running.

If you use ZoneAlarm, it will alert you that Apache is trying to act as a server. Allow it, and make sure ZoneAlarm remembers this.

Now, go to C:\Program Files\Apache\conf\ and open httpd.conf, the Apache configuration file. I change the following:

Directives Default My Setting Remarks
Port 80 θ This is an unused port unlikely to attract cracker attention.
ServerName localhost 127.0.0.1:θ 127.0.0.1 is the loopback address, a synonym for localhost; the port number θ is appended. The letter θ is a security precaution.
DocumentRoot C:/Program Files/Apache/htdocs C:/Documents and Settings/Owner/My Documents/My Web My local host pages are here. <Directory "C:/…"> must be changed to this, too.

PHP Scripting Language

The PHP scripting language began life in the late 1990's as a substitute for the inadequacies of CGI and JavaScript. It originally stood for Personal Home Pages; nowadays it is a recursive acronym: PHP Hypertext Processor.

PHP comes in a ZIP file, currently php-5.1.2-Win32.zip. Open it with WinZip and extract the whole thing into the folder C:\PHP.

PHP needs a configuration file, php.ini. There are two files, php.ini-dist and php.ini-recommended, which you can use simply by removing the text after the ini. The only thing you need to change in this file is extension_dir, which should be set to C:\PHP\ext\ (the case must be exact!). You need not change any thing else inside the configuration file (yet).

You do, however, need to change the Apache configuration file, so that the server knows that PHP is out there.

  1. Move the following files into the C:\PHP folder if they are not already there: php5apache.dll and php5ts.dll.
  2. Open the httpd.conf file and add the following lines in the appropriate spots:

    AddType application/x-httpd-php .php
    LoadModule php5_module "c:/php/php5apache.dll"
    AddModule mod_php5.c
    SetEnv PHPRC C:/php

  3. Restart the Apache server.

Now let's see if PHP works. With a text editor type <?php phpinfo(); ?> and save it in the root folder of your local site as phpinfo.php. Then fire up a browser and go to http://127.0.0.1:θ/phpinfo.php. If you see the PHP information page, then PHP works.

Finally, look at the extension_dir entry in the information page. If it says c:\php5, you're not done yet. If it says C:\PHP\ext, you're good to go.

MySQL Database Server

The MySQL database server is the world's most popular open source database, quoth the database's Web site. The fact that it's open source means you can download it for personal use without charge.

There is a graphical administration utility available separate from the server. You will need this if you are running MySQL on Windows, because it is a lot more difficult to manage MySQL otherwise (esp. when it crashes).

Visit the MySQL Download Center and download the latest version of MySQL for Windows, as well as the graphical client.

MySQL mysql-essential-5.0.18-win32.msi
Graphical Client mysql-administrator-1.1.7-win.msi

MySQL Server

install

  1. First, launch mysql-essential-5.0.18-win32.msi.
  2. The welcome screen will appear. Press Next.
  3. Setup Type. Consider yourself an advanced user. Choose Custom and press Next.
  4. Custom Type. Everything is chosen except the source code. Press Next.
  5. Ready to Install The Program. Press Install.
  6. A box will appear asking you whether you want to set up a MySQL account, log into an existing account, or skip signon. Skip it for now.
  7. The install is now finished. Press Finish.

configure

  1. The configuration wizard appears. Press Next.
  2. Choose "Standard Configuration" and press Next.
  3. Check "Install As Windows Service" and have it launch automatically. Leave "Include Bin …" unchecked. Press Next.
  4. Enter a root password, retype it, and set it so that root connects only from localhost (personal Web service). Do not set up an anonymous account. Press Next.
  5. You're ready: Press Execute.

MySQL Administrator

  1. Launch mysql-administrator-1.1.7-win.msi.
  2. The welcome screen will appear. Press Next.
  3. License Agreement. Read the legal boilerplate, which is basically the GNU Open Source License. Choose "I agree …." (in order to be able to) press Next.
  4. Destination Folder. Press Next.
  5. Setup Type. "Complete" is the default: Press Next.
  6. Ready to Install The Program. Press Install.
  7. Boom! You're done! Press Finish.

PHP

MySQL does not do you much good without a scripting language to mediate between your Web applications and the database.

PHP has two libraries for MySQL: The original library for MySQL versions before 4.1. The new library takes advantage of improvements to MySQL in versions 4.1 and up. Both libraries will will with the latest MySQL, but it is best to use the new library.

  1. Open C:\PHP\php.ini with a text editor.
  2. If you have not yet done so, change the value of extension_dir to C:\PHP\ext.
  3. In the Windows extensions list, uncomment (remove the semicolon from in front of) extension=php_mysqli.dll.
  4. Save your changes and close php.ini.
  5. Launch the following console command: apache -k restart. If you see no error messages, your settings have been accepted.

PHP/YAZ Z39.50 Client

Z39.50

Z39.50 is a transnational standard defining a protocol for computer-to-computer information retrieval. This client/server protocol is used largely by public, governmental and academic libraries worldwide for the catalogues of their collections. Z39.50 is overly complex and compares poorly with SQL and other means of retrieval. For that reason libraries and archives are the only users of this protocoll; that is why the agency that maintains it is the U.S. Library of Congress.

YAZ

YAZ is a programmer's toolkit for making applications using the Z39.50 protocol. Since it was first issued in 1995, YAZ is widely held to be the leading toolkit for building Z39.50 clients and servers, and has been proven in every conceivable type of employment.

YAZ is written in C, with libraries available in C++, Perl and PHP. This page deals with how to install YAZ with PHP 5.x.

PHP/YAZ

YAZ for PHP on the Windows platform is available in the library file php_yaz.dll. If you use PHP 4 you can download this straight off the PHP/YAZ site. For PHP 5.x, however, you must build php_yaz.dll yourself. I have done this with Visual Studio using the following steps. (When you are extracting, remember to preserve the folders in the archive.)

prepare

  1. Create a folder to put the YAZ material in. Here I name it PHP_YAZ.
  2. Go to the YAZ Web site, download the latest Windows version of YAZ (yaz_2.1.10.exe), and install it. Its default folder is C:\Program Files\YAZ.
  3. In the PHP/YAZ site, download yaz-1.0.2.tgz and extract its files into PHP_YAZ.
  4. In the PHP Downloads site, download php-5.0.4.tar.gz and extract its files and folders to PHP_YAZ.
  5. In PHP_YAZ make a folder yaz, in which make another folder include.
  6. Copy the contents of the folder C:\Program Files\YAZ\include\yaz\ into the PHP_YAZ\yaz\include folder.
  7. Copy the file yaz.lib from C:\Program Files\YAZ\lib to PHP_YAZ.
  8. Copy the file php5ts.lib from C:\PHP\dev to PHP_YAZ.
  9. In PHP_YAZ open yaz.dsp with a text editor.
    1. Change all references from \php-4.3.6 to .\php-5.0.4. Don't forget that initial '.', or Visual Studio won't find the references.
    2. Change all references from php4ts.lib to php5ts.lib.
    3. Change any references of ../../ to ./

After all this you should have a PHP_YAZ folder that looks something like this:

PHP_YAZ Folder

build

Now to build the PHP/YAZ library:

  1. Launch Microsoft Visual Studio.
  2. In the menu bar choose File, Open, File….
  3. In the Open box navigate to PHP_YAZ and open yaz.dsp.
  4. A box appears saying
    The project yaz.dsp needs to be converted to the Visual C++ 7.0 project format.
    Press Yes. You now have a PHP YAZ solution, which is what Microsoft calls a group of related projects in .NET.

distribute and test

You should be able to compile these files into the library php_yaz.dll. Once that is finished, copy php_yaz.dll into C:\PHP\ext.

You also want to copy yaz.dll from C:\Program Files\YAZ\bin to C:\PHP, as the yaz.dll that ships with PHP is too old.

Restart your computer. Then fire up a Web browser and visit phpinfo.php. The yaz module settings should be among those included in the PHP information listings.


Written by Andy West on 4 September 2005, based on separate Web pages written on 30 January 2005. Updated on 6 September 2006.