{"id":427,"date":"1997-09-09T01:36:29","date_gmt":"1997-09-09T09:36:29","guid":{"rendered":"http:\/\/www.birdhouse.org\/betips\/?p=427"},"modified":"1997-09-09T01:36:29","modified_gmt":"1997-09-09T09:36:29","slug":"cgi-basics","status":"publish","type":"post","link":"https:\/\/www.betips.net\/?p=427","title":{"rendered":"CGI\n basics"},"content":{"rendered":"<p>One of the more frequently asked questions I receive here at betips.net is &#8222;How do I set up a BeOS web server to do CGI?&#8220; The answer to this is no different from setting up CGI on any other POSIX platform, unless you&#8217;re working with attributes, in which case there are other details to be aware of (see the <a href=\"\/TrackerBase\/\">TrackerBase<\/a> page for more on that).<br \/>\nFirst of all you&#8217;ll need to be running a CGI-capable web server &#8212; anything but PoorMan will do (see <a href=\"http:\/\/www.bebits.com\/app\/322\/\">RobinHood<\/a>, or <a href=\"http:\/\/www.bebits.com\/app\/224\/\">diner<\/a> &#8212; <a href=\"http:\/\/www.david-reid.com\/apache\/\">Apache<\/a> is coming soon).<br \/>\nOnce your server is up and running, create a cgi-bin directory in the server&#8217;s root &#8212; this will store all of your bash, perl, or other scripts to be executed by the server. CGI, by the way, stands for Common Gateway Interface &#8212; a CGI script can be written in any language &#8212; even compiled C or C++, though perl is by far the most common language used in CGI implementations.<br \/>\nThe first line of your script always consists of the &#8222;magic cookie,&#8220; and points to the interpreter for the language the script is written in. For example, here are the magic cookies you would use for bash and perl scripts, respectively:<\/p>\n<pre>\n<\/pre>\n<p>Note that the magic cookie must include the full path to the interpreter, even if it&#8217;s already in your path.<br \/>\nYou must make your scripts executable with the chmod command (if you want to do this graphically, you can use Chris Herborth&#8217;s <a href=\"http:\/\/www.bebits.com\/app\/1293\">SetPerms<\/a>. Tracker add-on). If working from the command line, use:<\/p>\n<pre>\nchmod 755 filename.cgi\nor\nchmod a+x filename.cgi\n<\/pre>\n<p>The only other important thing to remember is that when you want results from the script returned as a web page, you must send the HTML header before you start spitting out HTML code. This will look like:<\/p>\n<pre>echo \"Content-Type: text\/html\"<\/pre>\n<p>in a shell script, or<\/p>\n<pre>print \"Content-type: text\/html\n\" ; <\/pre>\n<p>in a perl script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the more frequently asked questions I receive here at betips.net is &#8222;How do I set up a BeOS web server to do CGI?&#8220; The answer to this is no different from setting up CGI on any other POSIX platform, unless you&#8217;re working with attributes, in which case there are other details to be [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[10],"class_list":["post-427","post","type-post","status-publish","format-standard","hentry","tag-scripting"],"_links":{"self":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts\/427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427"}],"version-history":[{"count":0,"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}