KB 247: Difference between revisions
New page: ===Is there anything special I should know about running CGI scripts at SWCP?=== Article:247 Created:2003-08-27 22:39:06 Categories: Web Publishing ====Question or Symptom==== Does ... |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
===Is there anything special I should know about running CGI scripts at | ===Is there anything special I should know about running CGI scripts at SWCP?=== | ||
SWCP?=== | |||
Article:247 | Article:247 | ||
Created:2003-08-27 22:39:06 | Created:2003-08-27 22:39:06 | ||
| Line 18: | Line 17: | ||
of the website, so each person's CGI must be unique. Our convention is to | of the website, so each person's CGI must be unique. Our convention is to | ||
use the website owner's username with -bin appended. | use the website owner's username with -bin appended. | ||
For example, my username is jamii. Scripts in my CGI directory are | |||
referred to by /jamii-bin. If I have a CGI script named hello-world.pl I would | referred to by /jamii-bin. If I have a CGI script named hello-world.pl I would | ||
execute it with the following URL: | execute it with the following URL: | ||
| Line 104: | Line 104: | ||
That should solve the "Server Error 500". | That should solve the "Server Error 500". | ||
====Related URLS==== | ====Related URLS==== | ||
http://www.swcp.com/swcp/membersonly/cgi/ | http://www.swcp.com/swcp/membersonly/cgi/ | ||
http://www.swcp.com/swcp/html-links.php | http://www.swcp.com/swcp/html-links.php | ||
Latest revision as of 11:54, 4 June 2008
Is there anything special I should know about running CGI scripts at SWCP?
Article:247 Created:2003-08-27 22:39:06 Categories: Web Publishing
Question or Symptom
Does the script run as a special user, as my username, or as nobody? Where do I put scripts? How do I invoke them?
Resolution
CGI access must be enabled in order for you to run scripts. You can contact our technical support folks to arrange this. Once this has been set up for you there will be a subdirectory created in your public_html directory. It is named cgi-bin. This is where you'll upload your scripts. The scripts will execute as the owner of the website, so each person's CGI must be unique. Our convention is to use the website owner's username with -bin appended.
For example, my username is jamii. Scripts in my CGI directory are referred to by /jamii-bin. If I have a CGI script named hello-world.pl I would execute it with the following URL:
http://www.swcp.com/jamii-bin/hello-world.pl
This URL would most often go in the ACTION= field of a FORM.
There are pointers to several cgi-bin resources on the Net available from http://www.swcp.com/swcp/html-links.php. The page http://www.swcp.com/swcp/membersonly/cgi/ documents several pre-packaged cgi-bin programs which are on our server and availble for you to use, including imagemaps.
Here are some trouble-shooting tips for cgi-bin programs. 99% of all
cgi-bin problems are caused by one or more of the following things.
1. USE YOUR SCRIPTALIAS, NOT "CGI-BIN"
If we have set up a cgi-bin directory for you then we should have assigned a "scriptalias" for you as well. This is a name like "/username-bin/" which maps to the cgi-bin directory in your public_html directory. The purpose of the scriptalias is to execute your programs with your account permissions. That way your programs can read and write files which are owned by you without having to give global read/write permissions to those files. This is a major security concern. So, if your username is "sally", use "/sally-bin/program" to reference your program from HTML files, isntead of "/~sally/cgi-bin/program".
2. PERMISSIONS
The permissions on your scripts need to include "execute". You can do that with the chmod command in unix (e.g. "chmod +x filename") or your FTP program may support setting permissions on files remotely (some FTP programs support this, some don't).
If you like, you can ask help@swcp.com to set the appropriate permissions on the file for you. After they're set once, they should stay correct when you upload new versions of the file. As long as you upload over the old version (don't delete the old file first), it will keep the same permissions.
3. OWNERSHIP
This one is rare. Your cgi-bin programs need to be owned by you, and group ownership needs to match your default group. This is a security issue: if the system let you execute a cgi-bin script which was owned by someone else, then another person could modify the script to do things you wouldn't want it to do when it's running with your account priviledges (e.g. delete all your files, forward all your email to someone else, etc.) This probably usually only crops up if there are multiple people working on the same web site, or if a third party has been contracted to work on someone else's web site. If you're not sure how to get around this problem, email help@swcp.com and we can look at the situation and make a suggestion.
4. END-OF-LINE CHARACTER MISMATCH
Unix, Macintosh, and Windows all use different characters to denote the end-of-line. For normal HTML files this doesn't matter. But for perl scripts, it does. If you upload your script to our unix system from a Mac or Windows PC, it needs to have the line ending characters converted. You can do this by uploading the file in "ASCII" mode. Your FTP program should have an option for telling it to upload in ASCII mode instead of binary mode. Some FTP programs will also let you tell them that every .pl file should be uploaded in ASCII mode.
5. PARSE ERROR IN PERL PROGRAM
If you get the infamous "Server Error 500" when executing your script, it's usually because there's a syntax error in the script. If it's a perl program, the best way to find the problem is to run "perl -c" on the script. That will tell you if there is a syntax error, and roughly where to look to find it. For example:
perl -c myfile.pl Scalar found where operator expected at myfile.pl line 72, at end of line (Missing operator before ?)
Looks like line 72 of myfile.pl has some sort of problem. After fixing it:
perl -c myfile.pl myfile.pl syntax OK
That should solve the "Server Error 500".
Related URLS
http://www.swcp.com/swcp/membersonly/cgi/ http://www.swcp.com/swcp/html-links.php