NAME

Configuring Webdao.

Configuration is done via environment variables. The following variables is using:

For server lighttpd uses names respectively: WD_INDEXFILE, WD_ENGINE, WD_ENGINE_PAR, WD_SESSION, WD_STORE, WD_STORE_PAR, WD_DEBUG.

Configuring Web server

It supports all popular Web servers: IIS (isapi_fcgi.dll), nginx, lighttpd, apache.

The WebDAO suuports: cgi, FastCGi, mod_perl. The most productive is the mode FastCGI.

In the examples used the following initial conditions.

Setup standalone FastCGI

In the package WebDAO includes a script wd_fcgi.fpl ( /usr/local/bin/wd_fcgi.fpl for example).

To run an independent server using the following command:

#!/bin/sh
/usr/local/bin/wd_fcgi.fpl -d -l /tmp/myapp.socket -n 5 -maxreq 1000

For help use --help:

/usr/local/bin/wd_fcgi.fpl --help

Output:

Usage:
wd_fcgi.fpl [options]

    -d -daemon     Daemonize the server.
    -p -pidfile    Write a pidfile with the pid of the process manager.
    -l -listen     Listen on a socket path, hostname:port, or :port.
    -n -nproc      The number of processes started to handle requests.
    -m -maxreq     Number of request before process will be restarted 
                   -1 - unlimited. (defailt: -1)

nginx ( standalone FastCGI)

  • Simple example

        server {
            listen       80;
            server_name  example.org;
    
            charset utf-8;
    
            access_log  /var/log/nginx/example.org-access.log ;
    	error_log  /var/log/nginx/example.org-error.log  debug;
            root   /home/zag/www/;
            location ~ / {
                include        fastcgi_params;
                fastcgi_pass   unix:/tmp/webdao.sock;
                fastcgi_param wdSession WebDAO::Sessionco;
                fastcgi_param wdIndexFile index.xhtm;
            }
    
        }
  • An example of using a custom package of basic module

    For example, even if used as the name of the module: MySite. The constructor of this class as a parameter takes config - path to the configuration file.

        server {
            listen       80;
            server_name  example.org;
    
            charset utf-8;
    
            access_log  /var/log/nginx/example.org-access.log;
    	error_log  /var/log/nginx/example.org-error.log  debug;
            root   /home/zag/www/;
            #sample for static data
            #location ~* ^/(js|imag|img|data|data2|css|static|images)/ {
            #}
            location ~ / {
                include        fastcgi_params;
                fastcgi_pass   unix:/tmp/webdao.sock;
                fastcgi_param wdSession WebDAO::Sessionco;
                fastcgi_param wdIndexFile index.xhtm;
        	    fastcgi_param wdEngine MySite;
    	    fastcgi_param wdEnginePar config=/home/zag/www/mysite.ini;
            }
    
        }

apache (static + standalone FastCGI)

There are two modes. When use own manager FCGI (I <FastCgiServer>) and connection is made through FCGI socket.

Requires installation of the module mod_fastcgi:

mod_fastcgi-2.4.2

As part of the global httpd.conf want to add one of the required sections:

1 Static (FastCgiServer)
 <LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
    <IfModule mod_fastcgi.c>
    AddHandler fastcgi-script fpl fcgi
    FastCgiServer /usr/local/bin/wd_fcgi.fpl \
        -idle-timeout 3000 -flush -restart-delay 5 \
        -initial-env wdFCGIreq=1000 -processes 4 \
</IfModule>
2 Standalone ( FastCgiExternalServer )
<LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
 <IfModule mod_fastcgi.c>
 # Connect via net socket
 # FastCgiExternalServer /usr/local/bin/wd_fcgi.fpl -host localhost:60000
  FastCgiExternalServer /usr/local/bin/wd_fcgi.fpl -socket /tmp/myapp.socket
 </IfModule>

At VirtualHost section:

<VirtualHost>
   DocumentRoot /usr/zag/www
   ServerName example.org
   ErrorLog /var/log/example.org-error_log
   CustomLog /var/log/example.org-access_log common
   SetEnv wdEngine WedDAO::Kern
   SetEnv wdIndexFile index.xhtml
   SetEnv wdSession WebDAO::Sessionco

   #for use external storage
   #SetEnv wdStore WebDAO::Store::MLDBM
   #SetEnv wdStorePar path=/tmp

   RewriteEngine on
   AddDefaultCharset UTF-8
   RewriteCond     %{HTTP:Authorization}   ^(.*)$ [NC]
   RewriteRule     /.*             -       [E=HTTP_AUTHORIZATION:%1]
   <IfModule mod_fastcgi.c>
       RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
       RewriteRule ^/(.*) /usr/local/bin/wd_fcgi.fpl?$1 [QSA]
   </IfModule>
</VirtualHost>

lighttpd (standalone FastCGI)

var.engine = "ZagSite"
var.defaults = (
    "WD_SESSION"=>"WebDAO::Sessionco",
    "WD_INDEXFILE"=>"index.xhtm"
)
$HTTP["host"] == "example.org" {
server.document-root    = "/home/zag/www/"
setenv.add-environment =  var.defaults 
}
#use custom root class - MySite
$HTTP["host"] == "example.com" {
server.document-root    = "/home/zag/www/"
setenv.add-environment =  var.defaults + (  
    "WD_ENGINE" => "MySite",
    "WD_ENGINE_PAR"=>"config=/home/zag/www/mysite.ini" 
    )
}
#skip static 
$HTTP["url"] !~ "^/(js|imag|img|css|static)" {
   fastcgi.server = (
    "" => (
        "" => (
            "socket"      => "/tmp/webdao.sock",
            "check-local" => "disable"
                )
            )
        )

}

Work in cgi mode

For work WebDAO as CGI application use the script wd_cgi.pl

apache ( CGI )

<VirtualHost *>
   DocumentRoot /usr/zag/www
   ServerName example.org
   ErrorLog /var/log/example.org-error_log
   CustomLog /var/log/example.org-access_log common
   
   SetEnv wdIndexFile index.xhtm
   SetEnv wdEngine WebDAO::Engine
   SetEnv wdSession WebDAO::Sessionco
   
   RewriteEngine on
   RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
   RewriteRule ^/(.*) /usr/local/bin/wd_cgi.pl?$1 [QSA]
   <Directory "/usr/local/bin/wd_cgi.pl">
     AddHandler cgi-script cgi pl
     Options Indexes FollowSymLinks ExecCGI
   </Directory>
</VirtualHost>

Use from command line

To run from the command line using the script wd_shell.pl. In the process of being implemented using the environment variables.

Usage:
    wd_shell.pl [options] file.pl

     options:

      -help  - print help message
      -man   - print man page
      -f file    - set root [x]html file 

Options:

  -help   Print a brief help message and exits
  -man    Prints manual page and exits
  -f filename
          Set filename set root [x]html file for load domain

See also: WebDAO::Test.