Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!

Similar presentations


Presentation on theme: "Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!"— Presentation transcript:

1 Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!

2 Tools Used Windows XP service pack 3 computer GoDaddy account for hosting Domain name Filezilla for FTP access DOS to Unix conversion tool

3 The Dilemma I wanted to further master my web programming skills after completing HTML, Javascripting and PHP courses at Chaffey I signed up for Perl/CGI Hosted my website www.nickburns.com with GoDaddy after discussing my needs with them I then found for CGI, they use an Apache server! This created the need to learn how to convert DOS (Windows) derived files into Unix/Linux files so the server would be able to run them correctly

4 The Solution I found, after quite a bit of searching and testing, a simple and powerful utility which will translate “fromDOS” or “toDOS” based on the user’s needs Now, the process…

5 Build a Set of Files Build the html page first Point the html to the cgi file Upload the HTML page to the web server Build the CGI file(s) Convert the cgi file(s) into Unix type file(s) Upload the converted cgi to the web server using Filezilla  Change the cgi file attributes to 755  Disconnect from the server Test by connecting to the html web page

6 HTML Page Jubilee Book Club Jubilee Book Club Home Page Click the book to sign in Points to the CGI file

7 CGI Script (yes, it is a bit small; bear with me) #!/usr/bin/perl #book1.cgi - displays a sign-in form print "Content-type: text/html\n\n"; use CGI qw(:standard); use strict; #declare variable my $name; #retrieve Name cookie $name = cookie('Name'); print " \n"; print " Jubilee Book Club \n"; print " \n"; print " Jubilee Book Club Sign-In Form \n"; print "<FORM \n"; print "ACTION='book2.cgi' \n"; print "METHOD=POST>\n"; print " \n"; print " Name: \n"; print " \n";

8 CGI Script Described Shebang line  UNIX – #!/usr/bin/perl (be very careful to get this right; I once spent hours debugging a script only to discover I had typo’d on this line) File name and description of what the file will perform - #book1.cgi - displays a sign-in form Declare the type of page - print "Content-type: text/html\n\n"; - HTML for example Use the # for comments

9 CGI Script Described (continued) Use declarations - use CGI qw(:standard); - to tell Perl what module to use Prevent Perl from creating undeclared - use strict; Perl statements end with a semi-colon Declare variable - my $name; Add a cookie - $name = cookie('Name');

10 CGI Script Described (continued) Print/Return an HTML page Code in much the same way as a standard HTML page with print statements: print " \n"; print " Jubilee Book Club \n"; print " \n"; print " Jubilee Book Club Sign-In Form \n"; print "<FORM \n"; print "ACTION='book2.cgi' \n"; print "METHOD=POST>\n";

11 CGI Script Described (continued) print " \n"; print " Name: \n"; print " \n"; Remember to close each object! This cgi also points to a 2 nd cgi file containing the cookie, which will greet the customer

12 CGI Script Described (continued) Open the 2 nd CGI file in same manner as the first with a different file name: #!/usr/bin/perl #book2.cgi - displays a Web page containing the user's #name and the book information use CGI qw(:standard); use strict; #declare variables my ($name, $C_name); #assign input to variable $name = param('Name');

13 CGI Script Described (continued) Create the cookie: $C_name = cookie(-name => "Name", (input from the form) -value => "$name", (variable to save) -path => "/cgi", (path where to save the cookie) -expires => "+6M"); (how long to save the cookie) Send the cookie to the browser: print header(-cookie => $C_name);

14 CGI Script Described (continued) Create the response web page: print " \n"; print " Jubilee Book Club \n"; print " \n"; print " Hello, $name! \n"; print "The book of the month is \n"; print " \n"; print " The Case of the Missing Dagger \n"; print " by H.T. Sims\n"; print " \n"; Script is now complete

15 Format the CGI File(s) After following the simple directions in their readme file and installing “fromDOS”  Open a command prompt  Change directory to the location of the cgi file(s)  Type fromDos filename.cgi and press Enter The file is now compatible with Unix  Type perl –c filename.cgi and press Enter Perl starts the perl interpreter -c checks the syntax without executing  If no errors, proceed to upload

16 Uploading the CGI files Open Filezilla  Set up a connection to the server with appropriate user name and password  Left side window is location of local files  Right side window is location of server side files  Usually cgi-bin is the desired directory for cgi files, but GoDaddy uses CGI as their directory Upload the converted files to the server’s CGI folder Right click on the server files and select File Attributes Change attributes to 755 and disconnect when complete

17 Testing Open a Browser  Connect to the path of the HTML file uploaded  Complete the form as necessary  Determine if the results are as expected  Finished


Download ppt "Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!"

Similar presentations


Ads by Google