Inadequate planning on your part does not necessarily constitute a crisis for us
Home » Web Help » Supported Languages and Applications 

Printer Friendly Version  PDF Version 

Supported Web Languages


Can I use PHP?

Yes. You can check that PHP is working for you by copying the following text into a file in your public_html directory. Call it helloworld.php and make sure the file is world executable. Click here for an explanation of this

<?php echo "<center><b>Hello World!</b></center>" ?>

Click Here to see the output from the above script

NOTES:
Only PHP4 is supported on the CMS Unix systems. PHP scripts must end with the extension .php PHP scripts can be stored anywhere inside ~/public_html directory.
For more information on using PHP click here

Click Here to view some PHP tutorials

NOTE: PHP scripts will only run from stuweb.cms.gre.ac.uk
Can I use Perl/CGI?

Yes. Perl files must end in the ".pl" extension. Furthermore, these scripts must be placed in a directory in your public_html directory called cgi-bin.
Click here for instruction on creating the cgi-bin.
The cgi-bin directory must have its permissions set to 755 and the perl scripts contained within must also be set to 755. Click here for an explanation of this

Here is an example Perl/CGI script

#!/usr/local/bin/perl -w

use CGI qw(:standard);

print header();

print "<center><b>Hello World!</b></center>";
Or print the header explicitly as in:

#!/usr/local/bin/perl -w

use CGI qw(:standard);

print "Content-Type: text/html; charset=ISO-8859-1\n\n";

print "<center><b>Hello World!</b></center>";
Click Here to see the output from the above script

Click Here to view some Perl/CGI tutorials

NOTE: Perl scripts will only run from stuweb.cms.gre.ac.uk
I want to use a perl module that is not installed in the system Perl

If you want to use a Perl module that is not installed in the system Perl, what you have to do is install it locally in your home area and then tell the perl executable where to find that module in your Perl script.

The standard way to do this is to include the following line at the beggining of your Perl script

use lib "/path/to/perl/module";

Here is an example of the standard procedure to install Perl modules locally in your home area.

Create a directory in your home area called perllib

% mkdir ~/perllib
In the directory where you have downloaded the Perl module, unzip and untar the source file.

% gzip -d PerlMod-1.0.tar.gz
% tar xf PerlMod-1.0.tar
Change into the untarred directory.
% cd PerlMod-1.0
In this directory, there should be a README file and an INSTALL file along with the source for the actual Perl Module. Read the README and INSTALL files before carrying out the following steps!

To make the makefile you must do

% perl Makefile.pl PREFIX=~/perllib
The PREFIX specifies where the Perl Module will be installed (i.e. The perllib directory you created in your home area) Once this has completed successfully, you can run

% make
% make install
You will now be able to call this module by inserting the use lib statement in your Perl scripts.

Here is an example Perl script for the user wug01 using the Module we have just compiled.
#!/usr/local/bin/perl -w
use lib "/home/wug01/perllib";

use PERLMOD::Hello;

my $mod = new PERLMOD::Hello;
my $message = $mod->myMethod();

print "The output was $message\n";

Example Perl/CGI program taking data from an html form

Below is an example of how to take data from an html form and send it to a perl script for processing.

Here is the code for the form.

<form method="post" action="/cgi-bin/perlForm.pl">
Please Enter A Fruit: <input type="text" name="fruit">
<input type="submit" value="submit" name="submit">
</form>

Here is the code for the perl script.

#!/usr/local/bin/perl -w

use CGI qw(:standard);

my $fruit = '';
$fruit = param('fruit');   # Get the data contained in the 
if ($fruit eq '') {        # 'fruit' element of the html form
 $msg = "You forgot to choose a fruit!";
}
else {
 $msg = 'Sorry, we are all out of <b>' . $fruit .'\'s</b> at the moment';
}
print header();   # print out correct content header

print <<"EOF"
<html>
<head>
<title>Unix\@CMS :: Picking Fruit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../../styles.css" type="text/css">
</head>
<body>
<div class="content"><center>
<h2>$msg</h2><br>
<a href="http://unix.cms.gre.ac.uk/web/lang.html#perlform">go back for more
</a>.</center>
</div>
</body>
</html>
EOF

Fill in the box below with a fruit to see this script in action.

Please Enter A Fruit:

Debugging common Perl/CGI script errors. Can I look in the Apache error logs?

The best way to debug your Perl/CGI scripts is to run them from the Unix command line. Any errors in your script will be output to the screen giving a more detailed analysis than would be contained in the Apache error logs.

So, for a script named myScript.pl you would type the following command at the Unix shell prompt.

% perl myScript.pl

Here is an example using the helloworld.pl script shown above. This time we will insert an error into the code by mis-spelling the print statement on the last line.
#!/usr/local/bin/perl -w

use CGI qw(:standard);

print header();

prit "<center><b>Hello World!</b></center>";
Here is what we get when running this script on the command line.

% perl badworld.pl
Unquoted string "prit" may clash with future reserved word at badworld.pl line 7.
String found where operator expected at badworld.pl line 7,
near "prit "<center><b>Hello World!</b></center>""
        (Do you need to predeclare prit?)
syntax error at badworld.pl line 7, near "prit "<center><b>Hello World!</b></center>""
Execution of badworld.pl aborted due to compilation errors.

So, here we can see that there is an error on line 7 (including the blank lines) and that the perl executable doesn't understand the word "prit".

If you need to simulate passing parameters to the script - such as would be collected from an HTML form for example, you can do so by doing the following.

% perl myScript.pl arg1=foo arg2=bar

NOTE: A very common error in Perl/CGI programs is not including a correct content header for the browser to parse. One way to make sure you are printing out the correct content header (for html) is to import the CGI module as above and do a print header() statement. E.g.

#!/usr/local/bin/perl -w

use CGI qw(:standard);

print header();     # IMPORTANT!!

print "<center><b>Hello World!</b></center>";

Can I use WAP /WML?

Yes. The stuweb server is setup to serve .wml files - although you will need a WAP enabled browser to view them. Below is an example of using PHP to generate some WML which can be viewed on a WAP enabled device.

<?php
 header("Content-Type: text/vnd.wap.wml");   // Send the correct content/mime type
 echo "<?xml version=\"1.0\"?>";
 echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" 
                               \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
	
<wml>
<card id="hello">
<p>Today is
	
<?php
 echo date("m/d/Y");    // print out the date
 echo "<p></p><p>Greetings from the <br /><b>CMS Unix Team</b></p>\n";
?>
	
</p>
</card>
</wml> 
The output from this file can be viewed by visiting the following link with a WAP enabled device.

http://unix.cms.gre.ac.uk/web/wap.php


Developing code on your own machine?

If you are developing code on your own machine but will be demonstrating it on university servers, ensure that you test it on university servers well in advance of your demonstration.

Do not wait until the last moment.

Not all servers will run the same versions of software and if you wait until the last moment then it might be too late to get anything done in time.


Printer Friendly Version  PDF Version 

Home » Web Help » Supported Languages and Applications
University of Greenwich, a charity and company limited by guarantee,
registered in England (reg no. 986729). Registered Office: Old Royal
Naval College, Park Row, Greenwich SE10 9LS.