Web Design Beginning Web Page Design Advanced Web Site Design Web Site Management Professor Higgins Web Design Resources
     

CSC 112 - Lesson 3

Don't Reinvent the Wheel

The greatest thing about the web is what you can find on it. You can find graphics, programs, scripts, templates and just about anything that you might need to power a web site or web application. Some are free. Others are minimal cost and yet others are outrageously expensive. But if you look hard enough, you are likely to find something within your budget, even if your budget is zero.

I am not saying that you shouldn't write your own programs or make original graphics or anything like that but what I am saying is... if you don't have the time or the money to do it yourself, use programs and other tools to do what you want to do.

This is nothing new. I've heard that the difference between monkeys and men is, men (and women) use tools. All I am saying is that you should use the tools available to you on the web.

CGI-Scripts

There are many free CGI script sites where you can download ready made programs for things such as bulletin boards, chat rooms, shopping carts, games, email lists, calendars and just about anything else you might want your web application to do. The people who wrote these scripts spent hundreds and in many case thousands of hours writing these scripts so you don't have to.

Easy to do

Getting a scripts running on your site is relatively easy to do. The first time or two, you might make a few mistakes but after you do it a few times you'll be amazed how easy it actually is.

Perl

One of the main scripting languages for use in CGI is called Perl. Perl is a noncompiled language similar to HTML and JavaScript. The main difference is HTML and JavaScript are client side technologies (the code runs in your browser and loads when your page loads). Whereas Perl runs on the server so the server must be called whenever you run the program over the web.

Setting up a Perl Script in a Nutshell

1.) The first thing you need to do is to find a perl script that you want to use on your web site. Scour the search engines. Search for "free perl scripts", "free cgi scripts" or just "perl scripts"

A few places to start are:

2.) Download the script that you want to use to your computer. It will be in one of 4 forms:

Text file - These are the most basic scripts. You may need to change the *.txt extension to *.cgi or .pl or your script may almost be ready to run. When you upload (or download) your script to your cgi-bin on you server, be sure to use the ASCII mode on your ftp program. CGI programs transfered in binary mode will not run in your cgi-bin. Edit you program in a simple text editor like Notepad.

Zip file - You all know this type. You download it to your computer. Then use your Windows or Macintosh unzipping program. In class we use WinZip, but you can use any zip program that you may have. Extract your program to the directory where you want to save your program. The upload it in the ASCII mode (see warning above).

TAR - TAR is like zip but for UNIX or Linux. You download it to your computer then upload it to the directory in your cgi-bin where you want it to go. On UNIX systems, you any type in the following command:

tar xvfp yourprogram.tar

The TAR program installed on your server will unpack all of your files and directories expanding them into their proper places inside of the current directory. TAR programs always use the *.tar extension. The letters "xvfp" in the TAR command tell the computer to extract the files and directories and to set the permissions to the original settings. The "x" is the command that tells TAR to extract the files. The "v" command tells TAR to output information about the status of the extraction during the process. The "f" tells TAR to use the tar filename as the source to be extracted and the "p" tells TAR to maintain the original permissions. After you do this command, all the files should be neatly in their folders.

GUNZIP - Many cgi-scripts are compressed for download in the GUNZIP format. Gunzip is like a supercompression program that compresses TAR files even farther. gunzip files always end in the *.gz extension. To open a gunzip file, in your command prompt simply type in:

gunzip filename.gz

or

gunzip filename.tar.gz

The first command will uncompress your file into a TAR file and you will need to use the tar method above to extract your files to finish the process. The second command will use gunzip and tar to do the same in one step. Be aware that using the second method may require that you set your permissions because the original permissions may not be maintained.

Note: You will need to use a TELNET or SSI program to get to the UNIX prompt on your server to untar or ungunzip your files. In class we use putty.exe which can be downloaded for free on the PuTTY Download Page.

To use putty, just type in your IP address or domain name and click the SSI box and click the open button. This will get you on the server. Use your password and login to get into your account.

If you need to, read UNIX Guru in 20 minutes to learn the simple UNIX commands you will need to get around on the server but I'll go over the basics here for you.

3.) Use the list command (ls) to see where you are and to see what directories and files are in the directory you are in.

To change to another directory use the change directory command (cd directoryname). On our class web site you will need to type in "CD www" then "CD cgi-bin" to get into the cgi-bin or you could have done it in one step by typing:

CD www/cgi-bin

When you get there, type in "Ls -l" to list all the files and directories as well as their permissions. Often copying and expanding your files into directories is not enough to make your scripts run. You may need to set the permissions and give users the appropriate rights to each of your files.

If you are having trouble getting you script to run and you just want to get everything working, type in:

chmod 777 *.*

to open everything up so permissions will be readable and writable to everyone. After you get your script running you can go back and redo the permissions.

Common Permission Settings
Permissions Command
User Group World
rwx rwx rwx chmod 777 filename
rwx rwx r-x chmod 775 filename
rwx r-x r-x chmod 755 filename
rw- rw- rw- chmod 666 filename
rw- rw- r-- chmod 664 filename
rw- r-- r-- chmod 664 filename

The value of the digit determines the permissions granted. Permissions consist of three digits:

  • 4 for Read
  • 2 for Write
  • 1 for Execute

By adding these digits together, you add up to the permissions that make up the number in the code. For example: 4 + 2 + 1 = 7, which is read, write, and execute. 4 + 1 = 5 which is read and write. The chmod "777 filename" command makes the file readable, writeable, and executable for the owner of the file (user). the group the file is in and the world.

In order to open your file for editing in UNIX, you will need to use a UNIX text editor. I usually use one called PICO that comes installed with UNIX

To edit your file, simply type in:

pico filename

Your file will open in the pico text editor for editing:

Editing your script

4.) Finding Perl - Sometimes the perl module is installed in different folders on deferent servers thus sometimes you may need to change the path to the perl module.

The first line of any perl script instructs the server where to find the perl module. Typically it looks like:

#!/usr/local/perl

or

#!/usr/bin/perl

In order to find the path to the perl module on your server, type in:

which perl

The server will tell you the closest perl module:

perl: /usr/bin/perl

Sometimes there are several versions of the perl module installed on your server. In order to see all of the perl modules on your system use the command:

whereis perl

This command might give the following output:

Perl: /usr/bin/perl   /usr/local/bin/perl    /usr/bin/perl4.036    /usr/local/bin/perl5.002

If you are looking for a specific version of perl to run your script, you should use the "whereis perl" command.

Edit the first line to make sure the path is right to the perl interpreter (module) on your server.

Saving your edited file

5.) When you are done editing your file, save your file by using the "control o" command. Hold down the control key and type the letter "o" and the server will ask you if you want to save your file. Type in the letter "y" for yes. You file is saved.

If you want to exit pico and not update your file, hold down the control key and type the letter "x". The server will ask you if you want to exit without saving the file. Type in the letter "y" for yes or the letter "n" for no.

Follow the Directions

For your first cgi perl script, try something simple first to give you a little experience before you jump in to something more complex. Try a script with only a one (or a few) files to learn.

That said, most programs that you download will have simple step by step instructions for installing the program. Be careful and follow the directions exactly. Usually the file will be called something like README.txt or INSTALL.txt. Use Notepad or some other text editor to read the file. I usually print this stuff out so it is easier for me to follow the instructions.

Some programs are easier to install than others. Some programmers write very good instructions and some don't. Since often times, you are getting the script for free, you can't expect much support so if you are having trouble with one script, try another.

Sometimes you might decide to buy a program to use instead of using a free one. When you purchase a program or the license to a program, often the company that wrote it will supply you with support. Sometime spending a couple of hundred dollars on a program might save you hundreds or even thousands of hours. Don't be afraid to spend a little money to save your time and sanity. I buy programs from time to time. It helps me get my tasks done much more quickly. Many of these programs have been thoroughly tested and may be more reliable than something you put together yourself. Keep an open mind. For more information about installing cgi scripts see The Most Simple Intro to CGI and Your First CGI Script from BigNoseBird.com.

Other languages and programs

Perl in not the only language on the web. You may find another that you are more comfortable with and prefer using. Try your hand at some others too. There are many free scripts on the web to chose from in just about every language available

Installing someone else's scripts is a good way to get started on some other languages. You not only get the benefits of the program and its features but also you get a chance to learn from the experts. What more could you ask? Experiment and learn. That's the way of the web and of life in general.

Languages that are available to learn on the web:

  • Perl
  • C and C++
  • AppleScript
  • Python
  • PHP
  • Tcl
  • UNIX Shell
  • Visual Basic
  • VBScript
  • JavaScript
  • DHTML
  • JAVA
  • and many more