Perl 101: How to install a basic Perl script on a Web server

by ServerWatch Staff

So now that you've got you're Web server up, you probably want to do more than simply serve static HTML, right? This step-by-step tutorial will show you the 'ins' and 'outs' of installing a Perl script on your Web server.

One of the first things I learned when I began to write HTML is that it is relatively simple to create a Web site. I have always thought that, given the time and resources, I could train a monkey of average intelligence to design a simple Web site. However, what HTML lacks is the ability to enable true interactivity on a Web server. In order to make a site dynamic, enabling it to accomplish "real" tasks, a more advanced scripting language and protocol must be used. That is the beauty of Perl and the reason it has become one of the more if not, the most popular languages on the Web.


Perl, which stands for Practical Extraction and Report Language, is an extremely portable language written to assist the programmer with common tasks with an emphasis on text manipulation. Perl is different from CGI. While Perl is a scripting language, CGI (Common Gateway Interface) is a protocol. CGI describes a process in which a client or an external program interacts with a Web server. A CGI program dictates and facilitates this interaction, or the passing of information back and forth. The majority of CGI programs are written in Perl, which explains Perl’s popularity, but they can be written in just about any language.

sAssumptions & Requirementss

Before I delve too far into the process, I have made two assumptions. The first and most important assumption is that you have access to a server with a version (preferably the latest) of Perl installed. Second, I have to assume that you are comfortable downloading and installing software on your computer.


There are four critical ingredients to installing a Perl program: a text editor, an FTP program, a server, and a Perl script. Although virtually any text editor will do, the more code you write, the more comfortable you will want to be with your program. Personally, I recommend Super NoteTab or TextPad for the Windows platform, although your systems Notepad will suffice. For MacOS users you also have several options, from Mactext to BBEdit. Whichever program you decide to use--no matter which platform you are on--you will want to make sure that you have word wrap disabled. There are probably as many FTP programs available as there are Text editors. For windows, CuteFTP (my favorite) or WSFTP will get the job done, and for the Mac nothing can match the functionality of Fetch. The last ingredient is a simple Perl program. Although the program we are going to work with in this article is relatively simple in what it accomplishes, it will help to illustrate some key points you will need to consider when working with Perl.

The first thing you need to do before you begin working on the program is to properly understand your FTP software. A large percentage of the errors encountered when installing a Perl program come from improper use of the FTP program (telnet will not be covered). Your FTP software is a crucial component of installing a Perl program as it is what enables you to assign the program the appropriate permissions or security settings. The permissions of programs or files tells the server what the file is capable of doing or not doing. For example, if I want to write a program that modifies a text file, I need to set the permissions accordingly for the specified text file. If they are set incorrectly the server will not be able to write or append data to it. Almost all of the interfaces of the various FTP programs are strikingly similar. Under most circumstances, we will select a file or folder, usually just by clicking on it once to highlight it, and then go to one of our menu items to access our file permission settings. We want to find the command labeled "file attributes" or "permissions." This will bring up a dialog box that will present us with a series of check boxes for Owner, Group, and Public permissions. These three different categories allow you to specify permissions for each category of Read, Write or Execute.

If we break these down numerically, the number 4 means read, the number 2 means write and the number 1 means execute. You add these numbers together to grant or give permissions to each category (Owner, Group, or Public). If we were to chmod xyz somefile.txt (normally you would chmod or set a program's permission to 755), the owner’s permissions are defined by the x number, group permissions are defined by y, and z refers to everyone else or the public. Let’s take this a step further and say that we want to chmod 755 somfile.txt. We are giving the owner 7 (4 + 2 + 1 = read/write/execute), the group 5 (4 + 1= read/execute), and everyone 5 (4 + 1 = read/execute). Let’s plug this into our matrix to better understand what it is we are doing:

Owner (x)Group (y)Everyone (z)
Read (Value of 4)xxx
Write (Value of 2)x
Execute (Value of 1)xxx