Download - Chapter 2 Getting Started
![Page 1: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/1.jpg)
1 Copyright © 2002 Pearson Education, Inc.
![Page 2: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/2.jpg)
2 Copyright © 2002 Pearson Education, Inc.
Chapter 2
Getting Started
![Page 3: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/3.jpg)
3 Copyright © 2002 Pearson Education, Inc.
What You Need to Get Started
Getting the appropriate FTP or Telnet software Connecting to the Web server Setting up your directories. Getting the location of the Perl interpreter.
![Page 4: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/4.jpg)
4 Copyright © 2002 Pearson Education, Inc.
Connecting with Telnet
Connect to the Internet Start Telnet.
» On a Windows PC start Microsoft Telnet for Windows by clicking Start, Run, telnet.
Connect to your Web server with Telnet. Log into the server.
![Page 5: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/5.jpg)
5 Copyright © 2002 Pearson Education, Inc.
An Initial Telnet Sreen
![Page 6: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/6.jpg)
6 Copyright © 2002 Pearson Education, Inc.
Successful Telnet Login
![Page 7: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/7.jpg)
7 Copyright © 2002 Pearson Education, Inc.
Connecting with FTP
Connect to the Internet. Start FTP. Connect to your Web server with FTP.
![Page 8: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/8.jpg)
8 Copyright © 2002 Pearson Education, Inc.
An Initial FTP Login Screen
![Page 9: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/9.jpg)
9 Copyright © 2002 Pearson Education, Inc.
A Successful FTP Login Screen
![Page 10: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/10.jpg)
10 Copyright © 2002 Pearson Education, Inc.
Navigating UNIX Directories
/ - Operating system files/
home /home - ISP User directories
perlpgm /home/perlpgm -My files
and directories
bin etc . . .Some UNIX system
directories
usr
jsmith/home/jsmith -
jsmith's files and directories.
. . .
![Page 11: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/11.jpg)
11 Copyright © 2002 Pearson Education, Inc.
Navigating UNIX Directories - 2
/home/perlpgm /home/perlpgm -My files and directories.
/home/perlpgm/perl-pgm-www/cgi-bin- Where I need to place my web application
programs.
data
cgi-bin
/home/perlpgm/perl-pgm-www -Where I need to place my HTML files.
perl-pgm-www/home/perlpgm/data -A directory I place data I want on
the server but not on the Internet.
![Page 12: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/12.jpg)
12 Copyright © 2002 Pearson Education, Inc.
Some UNIX Navigation Commands
Command Command’s Effect
pwd Prints the Working Directory. Outputs the directory path of the
current directory.
ls LiSts the files and directories in the current directories. Returns all
of the files and directories in the current directory.
cd dir_name Changes the Directory to the directory named dir_name. Changes
the current directory to the one you specify. (Note that you can
navigate up one directory by executing cd .. —that is, cd
followed by two periods.)
![Page 13: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/13.jpg)
13 Copyright © 2002 Pearson Education, Inc.
Some UNIX Navigation Commands
UnixCommands
![Page 14: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/14.jpg)
14 Copyright © 2002 Pearson Education, Inc.
Navigating UNIX Directories with FTP
Homediron web server
C:\Tempon PC
![Page 15: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/15.jpg)
15 Copyright © 2002 Pearson Education, Inc.
Finding The Location Of Perl
Perl interpreter
» A program that translates Perl program commands into commands that are understandable to a computer.
» Runs your Perl programs and generates any output.
» Its command name is simply perl.
» It can be installed in any of several places on a Web server.
![Page 16: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/16.jpg)
16 Copyright © 2002 Pearson Education, Inc.
Finding Location Of Perl
Find the location of Perl Interpreter Telnet onto Web Server enter:
» which perl » where is perl
Perl InterpreterLocation
![Page 17: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/17.jpg)
17 Copyright © 2002 Pearson Education, Inc.
Starting Your Program Development Process
Each time you develop and run a program:» Create a program file and copy (or save) it into the
correct directory.» Change your program’s access permissions.» Check your program’s syntax. » Run your program.
![Page 18: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/18.jpg)
18 Copyright © 2002 Pearson Education, Inc.
Create Your Program File
Editors are computer applications that enable you to create, change, and save files» Microsoft Windows, Notepad is a simple editor
that works well for Perl development.
» On UNIX systems, the Pico, Vi, and Emacs editors are popular choices.
» Will describe the use of Pico on a UNIX Web Server.
![Page 19: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/19.jpg)
19 Copyright © 2002 Pearson Education, Inc.
Starting Pico
Telnet into Web Server and enter “pico”
![Page 20: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/20.jpg)
20 Copyright © 2002 Pearson Education, Inc.
Starting Your First Program
Start Editor and enter the following:1. #!/usr/bin/perl 2. # This program prints out a simple
message
3. print “Steady Plodding Brings
Prosperity\n”;
![Page 21: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/21.jpg)
21 Copyright © 2002 Pearson Education, Inc.
Program Entered in Pico
![Page 22: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/22.jpg)
22 Copyright © 2002 Pearson Education, Inc.
Run The Program
Save the program file on the web server. Enter the full path to the program file to run. For example
» /home/perlpgm/perl-pgm-www/cgi-bin/simple1.cgi
Program File
Home Directory
Directories On Web Server
![Page 23: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/23.jpg)
23 Copyright © 2002 Pearson Education, Inc.
Change the Program’s Permissions On A Unix Web
Server
UNIX access permissions are used to define the access rights of your files» read permissions define if the file can be read» write permissions define if the file can be changed, » execute permissions define if the file can be
executed as a program You set access permissions for your user ID,
your user ID’s group, and everyone else
![Page 24: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/24.jpg)
24 Copyright © 2002 Pearson Education, Inc.
Use The chmod command
chmod 755 /home/perlpgm/perl-pgm-www/cgi-bin/simple1.cgiThe UNIX chmod
commandchanges
file permissions
Your personal access permissions to the file.
Your group's access permissions to the file.
Any other user's access permissions to the file.
The file that you are changingread, write, and execution access
permissions to.
![Page 25: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/25.jpg)
25 Copyright © 2002 Pearson Education, Inc.
Use The chmod command
Digit Permissions Meaning
7 Gives read, write, or execute access to the file
6 Gives read or write access to the file, but not execute access5 Gives read or execute access to the file, but not write access4 Gives read access to the file, but not write or execute access
![Page 26: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/26.jpg)
26 Copyright © 2002 Pearson Education, Inc.
Change the Program’s Permissions On A Unix Web
Server
» chmod 777 simple1.cgi - end-user and his/her work group and anyone else to read, write, or execute the file simple1.cgi.
» chmod 755 simple1.cgi - end-user can read, write, or execute the file simple1.cgi, but everyone else can only read or execute it.
» chmod 644 simple1.cgi - you can read or write the file simple1.cgi, but everyone else can only read it. (Good for data files).
![Page 27: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/27.jpg)
27 Copyright © 2002 Pearson Education, Inc.
Setting Permissions with FTP on a UNIX Web Server
1. Log into the Web server using the FTP command.
2.Navigate to the appropriate directories on the Web server.
3.Select the file you want to change on your Web server, then right -click it. A drop-down menu will appear. Select FTP commands, and then chmod. (See Next Slide).
4. Select the desired read, write, and execute access permissions for your user ID, your group, and anyone else.
![Page 28: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/28.jpg)
28 Copyright © 2002 Pearson Education, Inc.
An FTP Change Permission Screen
![Page 29: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/29.jpg)
29 Copyright © 2002 Pearson Education, Inc.
Check and Correct Your Program’s Syntax
syntax checking - verifies that program statements are grammatically correct as specified by the program language grammar» Check the syntax of your programs before
attempting to run them.
![Page 30: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/30.jpg)
30 Copyright © 2002 Pearson Education, Inc.
To Check Your Program Syntax
(on a UNIX Web Server) establish a Telnet session, navigate to the directory that contains the file, enter perl –c filename, where filename is
the program file whose syntax you want to. For example,
–cd perl-pgm-www/cgi-bin–perl –c simple1.cgi
If no syntax errors then receive:– simple1.cgi syntax OK
![Page 31: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/31.jpg)
31 Copyright © 2002 Pearson Education, Inc.
Program with Syntax errors
Missingquote mark
![Page 32: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/32.jpg)
32 Copyright © 2002 Pearson Education, Inc.
Running Your Program
At least two different ways to run your Perl programs:» Directly on a Web server or PC without a
browser» Using your browser over the Internet.
![Page 33: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/33.jpg)
33 Copyright © 2002 Pearson Education, Inc.
Running Your Program - On A PC
1. Open a MS-DOS prompt window. » Click Start, Run and then enter command.
2. Run the program. » At the MS-DOS prompt, enter the location of Perl, followed
by the location of your program:» C:\Perl\bin\Perl C:\temp\simple1.pl» Perl C:\temp\simple1.pl » You Can also use cd
–cd C:\temp
–Perl simple1.pl
![Page 34: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/34.jpg)
34 Copyright © 2002 Pearson Education, Inc.
Getting Ready to Run Your Program Over the
Internet
1. To use a browser over the Internet, add the following MIME content-type line:
print “Content-type: text/html\n\n”;.
1.#!/usr/bin/perl
2.print “Content-type: text/html\n\n”;
3.# This program prints out a simple message
4.print “Steady Plodding Brings Prosperity\n”;
![Page 35: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/35.jpg)
35 Copyright © 2002 Pearson Education, Inc.
Change Program Process
1. Edit the program
2. Change the program.
3. Save the file.
4. Check the program’s syntax.
5. Run the program.
![Page 36: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/36.jpg)
36 Copyright © 2002 Pearson Education, Inc.
Running Your Program Over the Internet
1. Connect to the Internet.
2. Start your browser.
3. Enter the URL or Web address to your file
4. Check the program’s syntax.
5. Run the program.
For example, assume saved the in a file called simple2.cgi in my cgi-bin directory on the Web server. Can execute by the following: http://perl-pgm.com/cgi-bin/simple2.cgi
![Page 37: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/37.jpg)
37 Copyright © 2002 Pearson Education, Inc.
Output Of Program Executed Over the Internet
![Page 38: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/38.jpg)
38 Copyright © 2002 Pearson Education, Inc.
Dealing with Problems
Many Web servers redirect the errors from CGI programs into a separate error log located on the server. » You may receive a generic, cryptic message
when running program’s with errors. » Two common messages are Internal Server
Error (Figure 2.17) and 500 Server Error.
![Page 39: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/39.jpg)
39 Copyright © 2002 Pearson Education, Inc.
Some Things to Check Verify the program syntax. Verify the access permission. Verify the file has the proper extension. Verify the program is stored in the correct directory. Verify the correct Web address to your program. Verify the first line has the correct of the Perl
interpreter. Confirm the accuracy of your MIME Content-type line.
![Page 40: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/40.jpg)
40 Copyright © 2002 Pearson Education, Inc.
An Internet Server Error
![Page 41: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/41.jpg)
41 Copyright © 2002 Pearson Education, Inc.
Generating HTML Statement from Perl
Programs
1. #!/usr/bin/perl2. print "Content-type: text/html\n\n";3. print "<HTML> <HEAD> <TITLE> Example </TITLE></HEAD>";
4. print "<BODY>";5. print "<B><Font Size=5>This is a Test </FONT></B>";
6. print "A very Interesting test";
7. print "</BODY></HTML>";
![Page 42: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/42.jpg)
42 Copyright © 2002 Pearson Education, Inc.
Program Output
![Page 43: Chapter 2 Getting Started](https://reader036.vdocuments.net/reader036/viewer/2022062408/56813c7f550346895da61e57/html5/thumbnails/43.jpg)
43 Copyright © 2002 Pearson Education, Inc.
Summary
There are several different configurations you can use to develop CGI/Perl programs.» Using FTP and Telent are common
Steps to create a program: create with editor, enter program, set permissions, check syntax, and run the program.
Two statements are required:» First line identifies Perl interpreter location.
» Second line specifies the MIME Content-type.