- Home
- Webhosting
- Cgi
CGI scripts on your homepage
CGI scripts on your homepage
Common Gateway Interface scripts are applications who are - just as HTML-documents - installed on the server.
Generally they're used to process the input of forms or clickable maps
but they can be engaged in a broad field of purposes, of which the author whishes the user to initiate them by means of the browser:
The querying of a database, calculation of a value etc... CGI scripts can be written in for instance Perl, C, C++, the Unix Bourne Shell,
the C Shell etc... You yourself can write them or you can copy them from others.
Gateway scripts are usually found on system level. The actual CGI scripts need to be placed in a specific directory by the user.
They're processed by the specific servers. Do the following:
- create a subdirectory cgi-bin in your WWW-directory
using the command
mkdir ~/WWW/cgi-bin
- place the scripts in this subdirectory
- make sure the permissions
are set as follows:
- for your home directory:
rwx--x--x
To do so, from your home directory use the command:
$ chmod 711 .
- for the subdirectories WWW and cgi-bin:
rwx--x--x
To do so, from your home directory use the commands:
$ chmod 711 WWW
$ chmod 711 WWW/cgi-bin
- For the CGI-files:
rwx-rx-rx
Use from the WWW/cgi-bin directory e.g. the commando:
$ chmod 755 script.cgi
The script will be processed by means of a URL of the type:
http://users.UGent.be/~username/cgi-bin/script.cgi
The script has to be named with extension .pl or .cgi. If not, it won't be identified as such.
Possible files must be writable/readable for yourself only.
At the use of scripts, you might bump in to this error:
Internal Server Error
Error: Malformed header from script.
First, run your script at the Unix-prompt before addressing it through a WWW-browser.
This gives you an idea of the error. You can do this using the command
./scriptname
General recommendations
s
- It is important the scripts contain a Content-type declaration
- The ^M which might be created because of not working on a unix platform can simply be removed by
cat script | tr -d ^M > betterscript
The ^M is created by sequentially typing Ctrl-V and Ctrl-M (on linux)
- As to permissions: all user folders- and files
need to have the own username as user and as group the users group (not: www-data)
This can be easily checked with ls -alR /users/u/username
This can be changed with chown username:users /users/u/username -R
(for the username this needs to be done by a System Administrator)
- Can only be writable by the owner = the user
This can be easily checked with ls -alR /users/u/username
This can be changed with chmod wo-w /users/u/username -R
- Please attach possibly working scripts when you contact the helpdesk.
Running the script form the Unix-prompt doesn't work:
- Check the script's the permissions , they have to be set as 755.
Changing can by means of the command
chmod 755 scriptname
- Is your script a perl-script, then, the 1st line has to be
#!/usr/local/bin/perl
- You copied your script in binary mode from a PC. If you did this, then, at the end of each line in your script, you'll a ^M, which causes
your script to run incorrectly. This can be solved eiter by editing the script using pico (add a character, remove again) and save or, transfer
the script again from the PC, but this time in ASCII mode. The ^M's should be gone then.
Running the script from the Unix-prompt works but your browser returns an Internal Server Error.
Possible causes can be:
- Only for students: You use the script to send a form by means of sendmail.
Op studwww this feature was disabled because of abuse.
- Incorrect permission of your script
or one of the higher lying directories. The directories should at least be 711 (drwx--x--x) and the script itself 755 (-rwxr-xr-x).
- Your script is not in the correct directory. It has to be in the directory ~/WWW/cgi-bin to be specific.
- In your script files that don't exist are address or can not be read or written. Check whether all used files are correctly created or can
be created by the script. A script is called by means of a URL of the form
http://server/~user/cgi-bin/script.pl
(in this case your script needs to have the extention .pl of .cgi)
The script runs under your own account and the used files need to be read/writable for your account only.
Lots of people use CGI scripts (Common Gateway Interface) on their homepage
(e.g. counters to register the number of visitors).
Again, here a few links to pages which offer more info:
Beware, scripts of Matt's Script Archive contain a few
security holes. Use the good alternatives on e.g.
http://nms-cgi.sourceforge.net/