APPENDIX D INSTALLING AND PERL MODULES

D.1 Installing Perl on UNIX/ Systems

Perl typically comes already installed on UNIX-type operating systems (UNIX, Linux, Solaris, MacOS X). One important piece of information is the location of the Perl interpreter, because we need that on the first line of our Perl scripts. In UNIX, you can use the following UNIX command

which perl

to determine the path to Perl. If Perl is not already installed, or if a newer version is desired, go to www.perl.org to find the latest version. You need to make sure your Web server software allows execution of scripts. Sometimes CGI execution for files ending in .cgi is already turned on in Apache; you can easily test this with a test script such as hello.cgi. If it turns out that CGI execution is not enabled, then you need to enable it. If you can use a system admin GUI, that would be the easiest. For example, you can start up the Apache Configuration program on a Red Hat Linux server console, as shown in Figure D.1, and navigate to the menus that control CGI execution.

Figure D.1 Red Hat Linux Apache Configuration program.

For Apache you can also manually edit the configuration file httpd.conf. The following directive,

AddHandler cgi-script cgi pl

tells the server to treat all files with the .cgi or .pl extension as CGI programs. Warning: if you use the Linux GUI to configure Apache, then you should not mess with the httpd.conf file manually.

© 2005 John Wiley & Sons, Inc 791 792 APPENDIX D INSTALLING PERL AND PERL MODULES

D.2 Installing Perl on Windows Systems

Web Server Software First, make sure a Web server is already installed. In most modern cases, IIS should be installed. For a server, IIS would be installed. For a personal (nonserver) computer, you will need to install IIS or PWS, depending on which Windows operating system you are running. For Windows 2000 or XP, you will need to install IIS; you might need at least the "Professional" edition of these Windows operating systems. For the older Windows 95, 98, or NT you will probably want to install PWS (Personal Web Server). See Microsoft's Web site, www.microsoft.com, for exact requirements to run the appropriate Web server software (IIS or PWS) on a personal computer. On a personal computer, to install PWS on Windows 98 or NT, you will need either the operating system installation CD, such as Windows NT or Windows 98 Second Edition or later; or you can go to Microsoft's Web site and download the PWS installer. Once you have the installer, the installation of PWS is straightforward. Just follow the installation wizard. The default home directory is usually \Inetpub\wwwroot\. On a personal computer, to install IIS on Windows 2000 or XP, assuming you have the required edition operating system (or else it would not have the functionality to run Web services), just run the installation from the CD.

Installing Active State Perl on Windows Because the language Perl continues to be improved, the Web site that holds the Perl downloads will also evolve. The instructions here do not have ultraspecific links, because such links will likely change over time. Note that any screen shots and menus might vary depending on your specific operating system and the current version of the Perl installer. Here are the overall steps. 1. Go to www.perl.org. 2. Look for the link to Perl for Win32/NT and click on it. This takes you to www..com (to which you could also go directly). 3. Clink on the link to download the latest version of ActivePerl. You should get a window resembling the screenshot in Figure D.2. (Disclaimer: The look of any Web site may change over time of course!)

Figure D.2 Downloading ActivePerl.

4. (Step 1 of download) Verify requirements: Make sure that your system satisfies the requirements listed on the Web page. For example, for Windows 95, 98, or ME you might need the Windows 2.0 installer. Note that this does not yet download the actual ActivePerl installer; that is done in the next step. This step only downloads a program to update your installation software. It is possible that you may not need to download anything from this page. Then proceed to the next download page by clicking on "Next" near the bottom of this Web page (or possibly by some other means).

© 2005 John Wiley & Sons, Inc D.2 INSTALLING PERL ON WINDOWS SYSTEMS 793

5. (Step 2 of download) Download the ActivePerl installer: Choose the appropriate version of ActivePerl. Read the instructions and pick the best version for your operating system. At the time this book was written, that version for Windows is MSI. Click the link. The ActivePerl installer will be downloaded to your hard drive; save it somewhere appropriate. 6. Run the ActivePerl installer (with some file name ending in .exe) from where you saved it (during Step 2 of download). You will be guided through a series of menus. In most cases, you will simply click Next. 7. Here are some notes on what you might encounter in these menus. On the first screen, you will first have to choose "Yes, I agree …" to accept the licensing agreement. On one of the screens, be sure to choose the option to save the ppm settings (this is the default choice). The ppm is the , which will be extremely useful when you want to install Perl packages (see Section D.4). Notice that one of the screens says that it will "Create script mapping for Perl". This is what enables a file that ends in .pl to be executed as a program by the Perl interpreter! (This answers the question of how the Web server knows that it should execute the .pl file as a Perl program.) The script mapping registry is also what needs to be modified if you want files ending in .cgi to be executed as Perl programs when called through the Web. The script mapping registry is different from the file association registry, which registers what program should open a file when the file icon is double- clicked. Note that the default will be that file extensions need to be .pl. 8. Write and put a short Perl program, say hello.pl, in the Web document tree (for example, in \Inetpub\wwwroot\hello.pl). Open a browser and access the URL //localhost/hello.pl. If you get the result of the Perl script (as opposed to the source text file), then apparently everything works, and you are done. 9. This following step is necessary only if your Perl test program did not work. If you get an “insufficient permission” error message, then you may need to enable executables in the Web server. • For IIS: • Open the IIS manager program as shown in Figure D.3 (usually found in Programs →Administrative Tools).

Figure D.3 CGI permissions on IIS.

• Find the "Default Web site" object in the tree, and right-click on it, selecting Properties. This brings up a large menu. Or, if you wish to give CGI execution permission only to specific subdirectories, then you should instead click on a subfolder of the "Web site" object. • Select Home Directory or Directory. • There are many items you can configure here. Under Execute Permissions, select Scripts and Executables. Click OK. • For PWS: • Open up the PWS manager (usually found under Programs → Accessories → Internet Tools),

© 2005 John Wiley & Sons, Inc 794 APPENDIX D INSTALLING PERL AND PERL MODULES

• Click on Advanced. • Highlight either the Home directory or a subfolder, and click on Edit Properties. • In the pop-up window, be sure "Execute" is checked in addition to "Read" and "Scripts". Click OK. 10. This following step is necessary only if your Perl test program did not work. If you get the source file returned, then the source was never executed as a Perl program. This is because the script mapping never occurred. (This is a common problem if ActivePerl is installed before the installation of PWS, or if an older version of PWS is installed.) You will have to edit the script mapping registry manually. • For IIS: • Open the IIS manager program (usually found in Programs → Administrative Tools). • Find the "Web site" object in the tree, and right-click on it, selecting Properties. This brings up a large menu. • Select Home Directory. • Click on Configuration…. • Click on Add.

Figure D.4 Extension Mapping on IIS.

• Edit as depicted in Figure D.4, using the appropriate location of the Perl interpreter. • For PWS: • You will need to run the regedit program. You can run this manually by going to the Windows menu Start → Run and typing the regedit command. • Navigate (by double clicking) HKEY_LOCAL_MACHINE → System → CurrentControlSet → Services → W3SVC → Parameters → Script Map. • Select menu option: Edit → New → String Value.

Figure D.5 Using the Registry Editor.

• Edit the new entry as depicted in Figure D.5, using the path to the Perl interpreter in the Data.

© 2005 John Wiley & Sons, Inc D.4 EASY INSTALLATION OF PERL MODULES ON WINDOWS AND UNIX/LINUX 795

The default configuration of ActivePerl is that you will need a .pl extension for a source file to be executed as a Perl program. If you desire the .cgi extension, you can edit the registry as outlined in step 10 of the foregoing list, with .cgi instead of .pl. You can also make both entries! To make a directory accessible from the Web, right-click on the folder and select Properties. Then select the Web sharing tab as shown in Figure D.6. Check the Share this folder radio button. This will bring up another window that asks for an alias, read/write permissions, and execute permissions. Fill these in according to your needs. The alias means that the folder will now be accessible as a virtual directory in the Web document tree.

Figure D.6 Making a directory readable on the Web.

D.3 Installing MacPerl on Mac OS 9

Go to http://www.perl.org and find the link to install MacPerl, or go to http://www.macperl.com directly. Follow the instructions; it is straightforward.

D.4 Easy Installation of Perl Modules on Windows and Unix/Linux

On Windows, use the ppm program (Perl package manager), which should have been installed along with ActivePerl. At an MS-DOS command prompt, run the command

ppm

You will get a ppm prompt ppm>, and you may now execute ppm commands. The following command installs a specified package.

ppm> install package_name

You can get always get help with the help command.

ppm> help

© 2005 John Wiley & Sons, Inc 796 APPENDIX D INSTALLING PERL AND PERL MODULES

This will give you a list of commands, including how to search for names of Perl modules. For UNIX, you can use the analogous (Comprehensive Perl Archive Network; see www.cpan.org) command. To be able to run the cpan command requires installing the cpan module using the manual installation. See Section D.5 to learn how to install the cpan module. Once it is installed, running the UNIX cpan command gets you a cpan> prompt. You may now execute cpan commands. The following cpan command installs a specified package.

cpan> install package_name

If you have trouble getting the cpan command to work, try the following. • Try manually installing the Net::FTP module. • Use cpan to install Bundle::CPAN.

Using ppm or cpan is by far the easiest way to install a package. However, you should use the CPAN (http://www.cpan.org) Web site to find out what packages are available and to find descriptions of packages.

D.5 Manual Installation of Perl Modules on Windows and Unix/Linux

Note that some modules are already installed with standard Perl distributions. For example, the DBI (DataBase Interface) module comes installed with Linux 7.1. In Windows, it is much easier to do the easy installation using ppm. Note that ppm should have been installed along with ActivePerl. In Unix, one has to do at least one manual installation to install the cpan module (It’s the old chicken- and-egg problem). To install or browse to see what fun modules are available, go to http://www.cpan.org, which also has a link from http://www.perl.org. From the main page, you can browse or search for your desired module. Using the search method, you can type in a search string into the main search page (search.cpan.org, which is also linked from the main pages) and get a list of matching modules. For example, searching for "mail" yields many results, as shown in Figure D.7.

Figure D.7 A search for modules at CPAN.

© 2005 John Wiley & Sons, Inc D.5 MANUAL INSTALLATION OF PERL MODULES ON WINDOWS AND UNIX/LINUX 797

The lists give descriptions, authors, and release dates. In Figure D.7 the modules are the items with release dates. Clicking on one of them gets to the information page for that module. For example, Figure D.8 shows the information page for the DBD-mysql driver. You can see that there are many useful links, including documentation on usage and instructions for installation.

Figure D.8 A page for a module at CPAN.

To install a module manually, use the following steps: 1. Download the .tar.gz file. 2. Ungzip and untar this file into a directory of files. This collection of files also includes informative files. In Windows, use a tool such as WinZip. In UNIX, use the following UNIX command.

gzip -cd filename | tar xf -

3. Within this directory, run the following commands (in Windows, get to a command prompt).

perl Makefile.PL make make test

4. As long as the make test is okay,

make install

© 2005 John Wiley & Sons, Inc 798 APPENDIX D INSTALLING PERL AND PERL MODULES

D.6 Perl Modules Used or Mentioned in This Book

• DBI • DBD-mysql • DBD-CSV • DBD-ODBC • Mail::Sendmail • Mailtools (contains a bundle of several mail-related modules, including Mail::Mailer) • CGI (already installed with standard installations of Perl) • Bundle::XML • Soap::Lite

© 2005 John Wiley & Sons, Inc