Problem
If I click on a link on an HTML page to activate a cgi-bin script I have written, it does not execute.
It is an executable script and a cgi-bin script, which are commonly used on web servers, so why isn't it working?
Cause
Web servers, such as Netscape, may recognize a file containing a ".cgi" name as signifying that the script is a cgi-bin script, but do not execute it by default. The behavior and solutions can differ depending on the particular web server product.
Solution
As an example, first set up a web page and include a script.
If you connect to an SCO OpenServer 5 system using your browser with:
http://<servername>you should see the Welcome page for the Netscape Fastrack Server. This page is located at:
/usr/internet/ns_httpd/httpd-80/htdocs/index.htmlSwitch this page with your own, perhaps using the example below:
# pg index.html
<HTML>
<HEAD>
<TITLE>Welcome to my servers main page
</TITLE>
</HEAD>
<BODY TEXT="#103879" BGCOLOR="#FFFFFF">
<H2>
<A HREF="sayhello.cgi">Click to say Hello</A> </H2>
</BODY>
</HTML>This page references the script "sayhello.cgi" in the current directory. There is no default system directory in Netscape in which to put cgi-bin scripts on installation, but you can create one.
Create the cgi script:#!/bin/sh
echo Hello!Change its permissions:# chmod 755 sayhello.cgi
# ls -al sayhello.cgi
-rwxr-xr-x 1 root sys 21 Apr 26 15:52 sayhello.cgiIf you now connect to the server with your browser and click on the link, you should see this error:
Server ErrorThis server has encountered an internal error which prevents it from fulfilling your request. The most likely cause is a misconfiguration. Please ask the administrator to look for messages in the server's error log.
The following is an extract from Netscape Fastrack's documentation:
There are two ways to store CGI programs on your server machine:
You specify a directory that contains only CGI programs. The programs can have any names. You specify that CGI programs are all a certain file type. That is, they will all use the file extensions .CGI, .EXE, or .BAT. The programs can be located in any directory the server can serve from.
After you configure your server with either of these options, you move all of your CGI programs in the appropriate directory, or give them the appropriate extensions. You can also use both options simultaneously--you can have CGI-only directories and a CGI-specific file-type extension.
There are benefits to either implementation. If you want to keep a close eye on all CGI programs that you or anyone else might add, keep them in specified directories. If you don't need to keep watch that closely on your CGI programs, you could keep them in the same directories as your HTML files, and choose the file type alternative.
Note If you choose the directory option, your server will attempt to interpret any file you place in that directory as a CGI program. By the same token, if you choose the file type option, your server will attempt to process any files with the file extensions .CGI, .EXE, or .BAT as CGI programs. Depending on the text within the files, this will usually cause some kind of error.
See the "SEE ALSO" section below for information on how to find the Netscape documentation.
There are two ways to configure cgi-bin scripts on the Netscape Fastrack server.
The first way to configure cgi-bin scripts is to:
Connect to the Netscape Administration Server for that system with your browser:
http://<servername>:620Enter the login name as "admin" and the password that was created for the Administration server when it was installed. If the SCO OpenServer 5 operating system root password has been changed in the intervening time the later will not have changed. See other articles in this database to alter the password or allow remote access to the Administration Server.
Click on the green "80" symbol on the main screen.
Click on "Programs", "CGI-File Type".Set "Activate CGI as a File Type" to "yes". Save the settings.
The file "/usr/internet/admin/conf/srm.conf" contains a reference to "cgi" as an application type, but you need to activate it. The default directory where it looks for these files is left at "/usr/internet/ns_httpd/httpd-80/htdocs" by default.
Stop and restart the server:# cd /usr/internet/ns_httpd
# ./stop-admin
# ./start-admin
warning: daemon is running as super-user
startup: listening to port 620 as rootIf you click on the link now, it will still fail. The cgi-bin script needs some additions, change it to:
#!/bin/sh
echo "Content-type: text/html" <----------
echo "" <----------
echo Hello!BOTH lines are needed, it will fail without the "echo "" ".
Will other types of files execute?If the file is called "sayhello.sh" and the link is changed to:
...
<A HREF="sayhello.sh">Click to say Hello</A> </H2>
...it will fail, even though the contents appear to be a cgi script. The browser will attempt to download the file to your system.
If you create a C program called, for example, "sayhello.c" containing the following:
#include <stdio.h>main()
{
printf("Content-type: text/html\n");
printf("\n");
printf("<BODY>\n");
printf("Hello World\n");
printf("</BODY>\n");
printf("</HTML>\n");
}(Note: The "\n"'s are important.)and then compile it with "# cc -o sayhello sayhello.c" and create a link to execute it:
<A HREF="sayhello">Click to run a C program to say Hello</A>
</H2>it will display the binary code on your browser rather than displaying "Hello World".
Renaming the shell script or C program binary to <programname>.cgi will not work.
The second way to configure cgi-bin scripts is to:
Set a default cgi-bin directory. In this example, change to the directory "/usr/internet/ns_httpd/httpd-80/htdocs" and create a "cgi-bin" directory:
# mkdir cgi-bin
# chmod 755 cgi-binNow copy the cgi-bin scripts to this directory and update the index.html links to:
<A HREF="cgi-bin/sayhello.cgi">Click to say Hello</A> <A HREF="cgi-bin/sayhello">Click to say Hello World</A>
Again connect to the Administration Server, click on the "80" symbol, click "Programs", "CGI Directory".
Set the URL prefix as "/cgi-bin".Set the CGI Directory as:/usr/internet/ns_httpd/httpd-80/htdocs/cgi-binSave these settings on the server. The "/usr/internet/ns_httpd/ httpd-80/config/obj.conf file" is updated.
These settings make the link appear as:
http://<servername>/cgi-binwhen you move your mouse pointer onto the link in the browser, but the actual directory is below /usr/internet/ns_httpd/httpd-80/htdocs. If you set the CGI directory to "/cgi-bin", the browser will try to reference a UNIX directory called "/cgi-bin" to find the scripts.
The programs "sayhello.cgi", "sayhello.sh" and "sayhello" now
execute. See also
Online Help/documentation can be accessed by entering the Administration Server, clicking on "80", clicking on one of the topics such as "Performance Tuning", going to the bottom of the page and clicking on "Help".
Then click on "Contents" to get to the OpenServer 5 Netscape "Fastrack Server Administrators Guide" and "Programmers Guide". See the "Administrators Guide", "Chapter 8 Using Programs with your server" for details on installing cgi programs.
ta105892, "Where can I find online SCO Internet Family Documentation?"
ta105268, "How can I reset the Netscape Administration Server password for the Netscape Communications Server?"
ta105371, "How to enable remote access to the Internet FastStart Internet Manager."