
<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 executable.
</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>


