Plain CGI and PHP

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:

        php_exe_path = /usr/bin/php-cgi

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

        port = 80
        listen =
        allowed_scripts = php yaws cgi

Yaws will invoke the php-cgi binary and talk the CGI protocol to the binary.

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:

We have the following python file called foo.cgi:

#!/usr/bin/env python3

import cgi

print("Content-type: text/html\n\n")
print("<h1>hi there</h1>")

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.

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:

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


and then configure the appmod appropriately in yaws.conf. The default yaws.conf file contains an entry.

        appmods = <cgi-bin, yaws_appmod_cgi>        

Thus if we put put any executable files in the "cgi-bin" directory under the docroot, Yaws will speak CGI to those executables.

Valid XHTML 1.0!