How to develop software that runs on the laboratory server

This document describes how you can develop software that runs on the server of the laboratory of the SFB 504. In the following we will assume that you want to write a php3-script. The main steps, however, remain the same for any other development.

In principle it is possible to access the server from outside of the laboratory. However, you may find it more convenient to be physically present in the lab. Hence, let us assume that you are sitting in the laboratory.

Power on one or more computers. Choose LINUX as your operating system. Wait for the system to boot up and log in. Start the graphical environment with

startx

You want to edit files on the server. There are two ways of doing that:

Mapping files requires permissions that you possibly do not have, hence, it is perhaps easier to follow the second approach. To do that, you have to give the server's editor the permission to draw on your screen. Open an xterm and say
ssh -X yourusername@leibniz.sfb504.uni-mannheim.de
From now on, everything you type in this terminal will be executed on the server (until you type exit). The first thing you want to do is open an editor.
xemacs &
(Notice the ampersand at the end of the line - this means that you `get your shell back' even before xemacs is finished).

If you are not yet familiar with xemacs you may want to look at the xemacs-tutorial first. The tutoral can be invoced from within xemacs by pressing Control h and than the single key t (On german keyboards Control is sometimes called Strg). It will take you about 30 minutes to get used to the basic functions of xemacs. There are lots of functions that you will learn later, but for the time being the basics are sufficient.

Now let us assume that you plan to write a php script. To be executed by the httpd the script must be located in ~/public_html/ Now say C-x f and then public_html/somename.php3 to create a new file ~/public_html/somename.php3 If the directory public_html does not exist yet xemacs will ask you whether to create it.

Now you can edit your file. The following code may give you some ideas for a simple questionnaire (more examples can be found at http://www.kirchkamp.de/webexp.html:

<HTML> <BODY> <?php // the following file collects
all the data // make sure that your httpd may write to this file
$outfilename="test.out";

    // the function scale implements a scale of radio-buttons
    function scale ($varname,$comment) {
        echo "<TABLE><TR><TD WIDTH=250>$comment</TD><TD>";
        echo "   (is not the case) ";
        for ($i=1;$i<7;++$i) {
            echo $i;
            echo "<INPUT TYPE=RADIO VALUE=$i NAME=$varname>&nbsp;&nbsp;";
        }
        echo "(is the case)</TD></TR></TABLE>";
    }

    function ship ($varname) {
        global $outfile;
        global $$varname;
        fwrite ($outfile,$varname);
        fwrite ($outfile,"=\"");
        fwrite ($outfile,${$varname});      
        fwrite ($outfile,"\", ");
    } 

    echo "<FORM METHOD=POST ACTION=$SCRIPT_NAME>";
    // we first check whether the form was invoked for the first time:
    if ($Ready == "") {
        echo "Please fill in your age here:  <INPUT TYPE=TEXT NAME=AGE><BR>";
        scale ("RATEA","How do you rate A?");
        scale ("RATEB","How do you rate B?");
        echo "<P><INPUT TYPE=SUBMIT NAME=Ready VALUE=\"This is a useless button\">";
    } else {
        $outfile = fopen($outfilename,"a");
        ship ("AGE");
        ship ("RATEA");
        ship ("RATEB");
        fwrite ($outfile,"\n");
        fclose($outfile);
        echo "Thank you very much!";
    }
?>
</FORM>

</BODY>
</HTML>
The above script will generate the following form and also evaluate it:
Please fill in your age here:
How do you rate A? (is not the case) 1   2   3   4   5   6   (is the case)
How do you rate B? (is not the case) 1   2   3   4   5   6   (is the case)


Once you have finished editing your file (or you have reached a stage where you want to test it) save it with C-x w

Start netscape (on this or some other machine) and open URL http://leibniz/~yourusername/samename.php3

If it works, fine. If it doesn't, go back to your xemacs and debug your program ;-)

File permissions

A common problem may arise when your script reads or writes files. Since the httpd runs as a different user it may lack permissions to create files in your directories or to read them.
  1. Assume your script wants to write to a file test.out Enter the directory
    cd public_html
    create the file manually with
    touch test.out
    and allow everybody to write to that file with
    chmod a+w test.out
  2. Now assume that you want to read the file test.in Since it already exists you do not have to touch it. Still you have to make it world-readable with
    chmod a+w test.in
    In the case of a directory you have to say
    chmod a+wx ...

Oliver Kirchkamp
Last modified: Mon Jul 31 18:21:56 CEST 2000