l i v e c o d e

Setting up MC/Rev as a CGI
an iBlog (instructional blog)
Red Had Linux 7.2

Well, after having used MetaCard for years, and knowing the MC/Rev can be used as a CGI, I finally "took the plunge" and decided to get it set up so I could start scripting a CGI in a language that is most comfortable (I can do Perl, but I reallylike MetaCard).

The first thing I discovered is that ISPs (in general) don't want you to use anything but Perl as a CGI; their tech support people are trained in it, they have tools to help you get it working, and, for the most part, they don't understand why anyone would want to use anything else.

So I turned to my attention to all the notes I've collected over the years on using MC as a CGI and also spoke with Richard Gaskin of Fourth World, who is currently using MC as a CGI. Basically the steps boil down to these:

  1. Determine what operating system is running on the server that will host the CGI.
  2. Download the appropriate version of MC.
  3. Upload the MC engine to the cgi-bin folder of your web site.
  4. Upload the CGI script (basically a text file with a MetaCard script) to the cgi-bin folder as well.
  5. Set the permissions of both engine and script to 755
Sounds easy, no? Well, it may be for some, but it wasn't for me. My script was the most simplest of all, one that was put on the list by Mark (mark@bcesouth.com):
#!mc

on startUp
  put "Hello World!" into tResponse
  put "Content-Type: text/html" & crlf
  put "Content-Length:" & (the length of tResponse) & crlf & crlf
  put tResponse
end startUp
The name of the file was simple.cgi. I had made sure that since I was uploading to a UNIX server that I saved the file with UNIX line endings (I use a Windows tool called TextPad that does this for me).

The basic idea is that you call on this script file the same way as you would call on a Perl CGI (as part of the URL) and according to the code above, I should get "Hello World!" showing in my web browser when I execute this from the Address field of my browser (Internet Explorer 6/Windows, if you must know):

http://www.sonsothunder.com/cgi-bin/simple.cgi
Well, when I tried, it I got this:


The infamous "Internal Server Error 500" window

This is the infamous "Internal Server Error 500" window that you get which tells you there's a problem with your CGI. It doesn't tell you what is wrong; just that there's something wrong.

So I tried a few things and eventually asked people on the list what to do, including technical support at my ISP. Brian Yennie suggested I use Telnet to go and see if I can execute the CGI from the command-line by going to the directory and typing ./mc simple.cgi. I tried that, and got the error message:

linux: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory
This made me think that there was something wrong with a path I was providing, until Andu stepped up and suggested I use Telnet, go to the cgi-bin directory, and then check to see what libraries might be missing by doing a ldd mc command, and here's what it returned:
libXext.so.6 => not found
libX11.so.6 => not found
libm.so.6 => /lib/i686/libm.so.6 (0x40119000)
libc.so.6 => /lib/i686/libc.so.6 (0x4013c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
This told me I was missing two necessary library files for MetaCard to run as a CGI. I checked with my ISP to see if I could upload these files, and he informed me that I could upload them anywhere so long as I added the path to the location where the uploaded libraries could be found to my /etc/ld.so.conf file. Andu was kind enough to give me a copy of the two library files I was missing, so I created a directory at /usr/home/lib, uploaded the files there, and added usr/home/lib to the /etc/ld.so.conf file. Finally, I ran ldconfig (which you can do at any command prompt), which attached the two library files and made them available.

I then went back and tested by CGI from the Telnet command line by going to my cgi-bin directory and typing ./mc simple.cgi. Lo and behold, the words "Hello world!" appeared in my terminal! I excitedly tested this in my browser, and sure enough, it worked.


So let this be a lesson to you; your ISP may not have installed everything that the MC CGI needs to operate, but they should allow you to do the kinds of things I mentioned above. If they don't let you do this kind of stuff, you might want to try another ISP that will. (Mine is OLM.net, by the way, and they were very helpful.)

Posted 1/24/2003 by Ken Ray


Close this window Print this window