CGI-scripts.xhtml 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>Installing Kawa programs as CGI scripts</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="Servlets.xhtml" title="Installing web page scripts as Servlets"/>
  10. <link rel="next" href="HTTP-requests.xhtml" title="Functions for accessing HTTP requests"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Installing Kawa programs as CGI scripts" epub:type="subchapter" id="CGI-scripts">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Installing Kawa programs as CGI scripts</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p>The recommended way to have a web-server run a Kawa program
  23. as a CGI script is to compile the Kawa program to a servlet
  24. (as explained in <a class="link" href="Server-side-scripts.xhtml" title="Web page scripts">Server-side scripts</a>, and then use
  25. Kawa’s supplied CGI-to-servlet bridge.
  26. </p>
  27. <p>First, compile your program to one or more class files
  28. as explained in <a class="link" href="Server-side-scripts.xhtml" title="Web page scripts">Server-side scripts</a>. For example:
  29. </p>
  30. <pre class="screen">kawa --servlet --xquery -C hello.xql
  31. </pre>
  32. <p>Then copy the resulting <code class="literal">.class</code> files to your server’s
  33. CGI directory. On Red Hat GNU/Linux, you can do the following (as root):
  34. </p>
  35. <pre class="screen">cp hello*.class /var/www/cgi-bin/
  36. </pre>
  37. <p>Next find the <code class="literal">cgi-servlet</code> program that Kawa builds and installs.
  38. If you installed Kawa in the default place, it will be in
  39. <code class="literal">/usr/local/bin/cgi-servlet</code>.
  40. (You’ll have this if you installed Kawa from source, but not
  41. if you’re just using Kawa <code class="literal">.jar</code> file.)
  42. Copy this program into the same CGI directory:
  43. </p>
  44. <pre class="screen">cp /usr/local/bin/cgi-servlet /var/www/cgi-bin/
  45. </pre>
  46. <p>You can link instead of copying:
  47. </p>
  48. <pre class="screen">ln -s /usr/local/bin/cgi-servlet /var/www/cgi-bin/
  49. </pre>
  50. <p>However, because of security issues this may not work, so it is
  51. safer to copy the file. However, if you already have a copy
  52. of <code class="literal">cgi-servlet</code> in the CGI-directory, it is safe to make
  53. a hard link instead of making an extra copy.
  54. </p>
  55. <p>Make sure the files have the correct permissions:
  56. </p>
  57. <pre class="screen">chmod a+r /var/www/cgi-bin/hello*.class /var/www/cgi-bin/hello
  58. chmod a+x /var/www/cgi-bin/hello
  59. </pre>
  60. <p>Now you should be able to run the Kawa program,
  61. using the URL <a class="ulink" href="http://localhost/cgi-bin/hello" target="_top">http://localhost/cgi-bin/hello</a>.
  62. It may take a few seconds to get the reply, mainly because of the
  63. start-up time of the Java VM. That is why servlets are
  64. preferred. Using the CGI interface can still be useful
  65. for testing or when you can’t run servlets.
  66. </p>
  67. </section>
  68. <footer>
  69. <div class="navfooter">
  70. <p>
  71. Up: <a accesskey="u" href="XML-tools.xhtml">Working with XML and HTML</a></p>
  72. <p>
  73. Previous: <a accesskey="p" href="Servlets.xhtml">Installing web page scripts as Servlets</a></p>
  74. <p>
  75. Next: <a accesskey="n" href="HTTP-requests.xhtml">Functions for accessing HTTP requests</a></p>
  76. </div>
  77. </footer>
  78. </body>
  79. </html>