R. Clayton (rclayton@clayton.cs.monmouth.edu)
(no date)
To get the server to even find the script I had to do the following:
Probably the easiest thing to do is use the -c thttpd option to set the
name of the cgi-bin directory:
thttpd -c '/cgi-bin/*'
Note that even though the cgi-bin directory starts with a slash (indicating
an absolute path from root), it actually is relative to the directory in
which you are running thttpd. For example, if you're running thttpd in
/export/opt/cs-537/thttpd/thttpd-2.20b
and you give the -c option above, then the cgi bin is
/export/opt/cs-537/thttpd/thttpd-2.20b/cgi-bin
thttpd will do a bit of pattern matching on cgi files; /cgi-bin/*.sh will
only recognize files ending in .sh under cgi-bin as cgi-bin files; /cgi-bin/*
will recognize all files under cgi-bin as cgi-bin files. A double asterisk
enables cgi-bin files in all subdirectories under the current one; if you
organize your cgi-bin directory as
/cgi-bin/read-scripts/...
/cgi-bin/write-scripts/...
/cgi-bin/lock-scripts/...
and so on, you'll want to specify the cgi-bin as -c '/cgi-bin/**'
After making these changes, the server recognized that I was trying to access a
script, however all that the server would do is send the script file back to
the client.
Make sure user and other have read and execute permissions on the script:
cl ls -l
total 2
-r-x------ 1 rclayton faculty 342 Apr 30 15:30 printenv
cl chmod o+rx printenv
cl ls -l
total 2
-r-x---r-x 1 rclayton faculty 342 Apr 30 15:30 printenv
Subdirectories under cgi-bin only need user permissions set.
One other thing to watch out for here is the browser cache. If you're
testing thttpd with a browser and you get the wrong page, make sure you
disable or clear the browser cache, because otherwise you'll just keep
getting the same page over again as the browser serves itself out of the
cache rather than going back to thttpd. Because I've been bitten by this
several times, I test servers by telnetting into them.
On reading the documentation (meager that it is) I noticed that thttpd setup a
chroot 'jail' for its cgi programs - I though that this might be the problem
since the necessary files for script operation might be inaccessible. I
removed the chroot command from the thttpd.conf file, but the behavior of the
client and server was the same.
chroot jails only work when you run the server as root, which I hope you're
not doing because mucking around as root is dangerous.
third - From the same textbook, I downloaded a web page and an executable file.
The executable file should build a dynamic HTML page and send it back to the
client, displaying the environmental variables and their values.
See also cgi-bin/printenv in the thttpd directory.
When I click on the submit button on the web form, the client appears to do
something and then hang. On the LINUX server, I can see two thttpd processes
(which is to be expected if thttpd uses fork based concurrency),
You should only have one thttpd running at a time (you can have as many as
you want running, but it probably gets confusing when more than one are
running). I recommend running thttpd with the -D option to keep it from
running as a daemon by burrowing into background.
however using env I see no evidence of the expected environmental variables.
However, I am not sure if I would see these values since I do not know if
environmental variables are global in scope or if they have 'process scope'.
That matters not here because thttpd sets up the shell-variable environment
in which the cgi program runs.
fourth - From the LINUX box I attempted to open the web-page using netscape (I
had to give the fully qualified path to the file:
http://localhost/home/httpd/cgi2.html just for netscape to find it) however
when I clicked on the submit button I just got a 'file not found' error.
If I'm interpreting this right, the browser found the cgi2.html page but
didn't find something after you clicked on the submit button showing on the
cgi2.html page. Although I can't say for sure, it sounds to me like you need
to rewrite a url or two in the cgi2.html page.
1. based on the above experiments I do not know if my thttpd server is
functioning correctly or not. I am at a loss here, I am not a 'web master' and
certainly not a UNIX/LINUX guru. I have tied everything that I can think of to
get the expected behavior of CGI. I am not sure what went wrong or how to
proceed. Any suggestions of what to try?
Don't run as root.
Make sure the permissions are set correctly for the cgi scripts and cgi
directories.
Run thttpd in foreground using the -D option and use a nice, simple -c option
such as '/cgi-bin/**'. Also, don't forget to specify a port using the -p
option because, as it's not running as root, the default port 80 is not
available to thttpd.
Avoid browser cache problems by telnetting into thttpd for tests.
If you're faced with the prospect of learning something new, I recommend you
allot yourself plenty of time for the experience.
however the thttpd.conf had the following line in it: dir=/home/htppd/html to
get a web page to display I had to do either of the following: 1) add a html
directory to the /home/httpd/ directory 2) modify the dir parameter of the
configure file.
Ignore all that stuff; just make thttpd. The only directories that matter
are the cgi-bin directory and the cgi-bin directory's parent. You can put
the cgi-bin directory anywhere you want and run thttpd from within the
cgi-bin directory's parent.
This archive was generated by hypermail 2.0b3 on Sun May 06 2001 - 20:30:05 EDT