University homepage Suomenkielinen versio puuttuu Inte på svenska In english
University of Helsinki Department of Computer Science
 

Department of Computer Science

Intro

db.cs.Helsinki.FI (alias alkokrunni) is a database-oriented WWW server of the department. It is possible to run users' own CGI scripts on this server! This document is a brief introduction into this subject. Note the PHP supplement at the end.

First login

At the first login, a local home directory is created. File servers fs and group appear "readonly" as regards this server. This means that you can write files only locally.

The WWW server doesn't have access to your home directory by default. You can set it up with the command chmod a+x /home/username, for example.

Setting up public_html

As usual, users' files visible to the WWW server must be located in a subdirectory called public_html. A file in that directory is publically available.

CGI scripts aka cgi-bin scripts

For your CGI scripts you should (though strictly speaking you do not have to) create a cgi-bin subdirectory in your public_html directory. Now your CGI scripts (like hello.pl) can be run with a URL like http://db.cs.Helsinki.FI/~tjokela/cgi-bin/hello.pl. But wait...

Must have .htaccess file

If you do not have a .htaccess file with the following text in it

AddHandler cgi-script pl
you only get the code of your script! So, you must create that .htaccess file in the cgi-bin directory.

If you have another script called myscript.cgi in addition to hello.pl your .htaccess file should read

AddHandler cgi-script cgi
AddHandler cgi-script pl
Got it?

Note on permissions

For anything to work properly you must set access permissions correctly. "Read" for HTML files, "user execute" for Perl scripts, etc. See the following example.

For security reasons, don't give any other groups or users write access to the cgi-bin directory or its contents. The WWW server won't run your scripts if you do this!

If you want more privacy, you can use the wwwonly command for the public_html directory but DO NOT use it for the cgi-bin directory. WWW server requires the group of the cgi-bin directory to be your default group.

Correct permissions in order to run a CGI script are:

dr-x-----x /home/myacco
dr-x-----x /home/myacco/public_html
-r-----r-- /home/myacco/public_html/.htaccess
dr-x-----x /home/myacco/public_html/cgi-bin
-r-x------ /home/myacco/public_html/cgi-bin/hello.cgi

Now the hello.cgi can be accessed through Internet at http://db.cs.helsinki.fi/~myacco/cgi-bin/hello.cgi .

In essence, the Apache HTTP server user needs access to traverse all directories right down to your script, and be able to read any existing .htaccess files. If there's a .htaccess file the server can't read, nothing under that directory will be displayed.

The executable/script files themselves ONLY need permissions to be read and executed by the user (you). Your scripts will only ever run as you, with your access rights - the web server does not need access to even read them.

Any static content to be served from the same directory tree, like images, stylesheets, HTML and javascript files, still need the o+r (others can read) permission.

Finally

For more information on setting up WWW documents see the department's WWW guide (in Finnish).

Read also instructions and guidelines on users' own servers (in Finnish). CGI scripts are a potential security threat so be sure what your CGI scripts do, disable CGI scripts when you don't need them and remove unnecessary scripts.

The WWW server logs errors from your CGI scripts to file /home/www/userlogs/<yourlogin>.error.

If you uploaded a CGI script from a Windows system, there may be a problem with the text file format. You may need to use the dos2unix program before you can use an uploaded text file as a CGI script. More information on transfering files is available in Finnish on a web page.

Read the manual of the Apache WWW server if everything fails...


PHP supplement

PHP is used just like any other script language, i.e., Perl.

However, it needs no configuration other than correct permissions and ownership. Files with the ending ".php" under public_html directories are automatically executed as their owner through the /usr/bin/php-cgi translator.

Check access permissions. Try it. Check again...


Modified from Oskari Heinonen's original document http://db.cs.Helsinki.FI/~oheinone/cgi-howto.html.

Back to the computing facilities page

support@cs.Helsinki.FI