Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 104 lines (69 sloc) 2.429 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

<erl>
out(A) ->
       {ssi, "TAB.inc", "%%",[{"cgi", "choosen"}]}.
</erl>


<div id="entry">

<h1>Plain CGI and PHP</h1>

<p>
  Yaws supports plain CGI just fine. The two most common ways to run yaws cgi script is either as regular cgi scripts or as php scripts through the typical php-cgi binary. Yaws chooses how to ship a file based on file extension. Let's start with the php-cgi example. PHP files have the extension .php and if we enable php by indicating it in yaws.conf:
</p>


<div class="box">
      <verbatim>
        php_exe_path = /usr/bin/php-cgi
      </verbatim>
</div>

<p>And then also ensure that we have enabled php processing for the individual server as in:
</p>


<div class="box">
      <verbatim>

<server www.hyber.org>
        port = 80
        listen = 0.0.0.0
        allowed_scripts = php yaws cgi
        ....
</server>
      </verbatim>
</div>

<p>

Yaws will invoke the php-cgi binary and talk the CGI protocol to the binary.
</p>
<p>
        
Another common situation is that we write our CGI scripts in e.g. python and use python libraries to speak the CGI protocol. The easiest way forward here is to rename the python scripts with the extension ".cgi" as in this example:
</p>
<p>
We have the following python file called foo.cgi:
</p>


<div class="box">
      <verbatim>

#!/usr/bin/python

import cgi

print "Content-type: text/html\n\n"
print "<h1>hi there </h1>"
      </verbatim>
</div>
<p>

Since the file ends with the magic suffix ".cgi", Yaws will just invoke the file as an executable and speak CGI to it. Thus for this scheme to work we must also make the file exeutable.
</p>

<p>
Yet another common scenario is when have a set of CGI files not ending with the ".cgi" file extension. We can put all the CGI files in a common directory and define an appmod as follows:
</p>


<div class="box">
      <verbatim>

out(Arg) ->
    yaws_cgi:call_cgi(Arg, lists:flatten(Arg#arg.fullpath)).

      </verbatim>
</div>
<p>
and then configure the appmod appropriately in yaws.conf. The default yaws.conf file contains an entry.
</p>



<div class="box">
      <verbatim>

        appmods = <cgi-bin, yaws_appmod_cgi>
      </verbatim>
</div>
<p>
Thus if we put put any executable files in the "cgi-bin" directory under the docroot, Yaws will speak CGI to those executables.
</p>



<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>


Something went wrong with that request. Please try again.