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 plyou 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 cgiGot it?
AddHandler cgi-script pl
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.
tjokela@alkokrunni:~/public_html$ ls -la . cgi-bin .: total 16 drwx--x--x 3 tjokela 12006 1024 Oct 6 21:24 ./ drwx--x--x 3 tjokela 12006 1024 Oct 6 19:23 ../ drwx--x--x 2 tjokela 12006 1024 Oct 6 19:14 cgi-bin/ -rw-r--r-- 1 tjokela 12006 82 Oct 1 15:56 hello.pl cgi-bin: total 20 drwx--x--x 2 tjokela 12006 1024 Oct 6 19:14 ./ drwx--x--x 3 tjokela 12006 1024 Oct 6 20:45 ../ -rw-r--r-- 1 tjokela 12006 25 Oct 5 15:06 .htaccess -rwxr--r-- 1 tjokela 12006 72 Oct 1 16:06 hello.pl*
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.
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
Yes, PHP is available, too. PHP is used just like any other script language, i.e., Perl. Use the php file extension.
Php is not available as an apache module but only as CGI. This means that some PHP-based software doesn't work without modifications. You have to specify the PHP command interpreter on the first line of the script, or create a wrapper to process PHP files by extension. See the following examples.
Now your PHP scripts like hello.php (hello.php4; view the source to see the actual file content in your browser) can be run with a URL like http://db.cs.Helsinki.FI/~tjokela/cgi-bin/hello.php (http://db.cs.Helsinki.FI/~tjokela/cgi-bin/hello.php4).
Do not forget to add
AddHandler cgi-script phpor
AddHandler cgi-script php4to your .htaccess file.
Check access permissions. Try it. Check again...
Defining a php-cgi handler for PHP scripts in .htaccess:
AddHandler cgi-script cgi
AddHandler php-cgi php
Action php-cgi /~myacco/cgi-bin/php.cgi
Content of the (for example) ~/public_html/cgi-bin/php.cgi file:
#!/bin/bash
/usr/local/bin/php5 $@
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