Dedicated CGI on Apache
Assumptions
This scenario makes the following assumptions:
- This is a dedicated server and you have full control over the Apache configuration files.
- The server only hosts the Woof! application and nothing else.
- The application is rooted at the top level, i.e. http://www.mysite.com is the entry point into the application.
The Common Gateway Interface (CGI) adapter is used as it does not require any additional modules for Apache that are not part of the standard Apache distribution. This is the simplest possible configuration but one you should normally not use for performance reasons unless your site traffic is low volume. We describe it here as a basic introduction to the configuration process.
Step 1 - install Woof!
The first step is to install Woof! for Apache and CGI using installer - installation utility.
~/woof-dist> tclsh scripts/installer.tcl install apache cgi -installdir /var/myapp
This will create the Woof! directory structure under /var/myapp. In particular, the /var/myapp/public will contain the publically accessible directory tree that will be the document root for the dedicated web server. The file cgi_server.tcl in that directory implements the Woof! CGI interface. The other files in the directory, including subdirectories, are intended to be directly served by Apache without going through Woof! as detailed below.
Step 2 - set the document root
The next step is to configure Apache by editing its configuration file conf/httpd.conf (or whatever your system is configured for) in the Apache directory tree.
Since this is the only application on the server, the document root for Apache must be changed to point to the Woof! public directory by editing the definition of DocumentRoot in httpd.conf.
DocumentRoot /var/myapp/public
Note again that the document root points to the public subdirectory, not the Woof! root directory. By default, Apache will now look under the /var/myapp/public directory to locate URL resources.
Step 3 - configure CGI
We now add a Directory section to httpd.conf to set appropriate configuration for our directory including access control.
For Apache 2.2, this section should be:
<Directory "/var/myapp/public"> Order allow,deny Allow from all Options +ExecCGI AddHandler cgi-script .tcl RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ cgi_server.tcl/$1 [QSA,L] </Directory>
For Apache 2.4, this section should be:
<Directory "/home/vmuser/src/woof/dist/woof-0.5a1/public" > Require all granted Options +ExecCGI AddHandler cgi-script .tcl RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ cgi_server.tcl/$1 [QSA,L] </Directory>
The Options line enables CGI for the directory tree under public. Together with the AddHandler line, it will allow the public/cgi_server.tcl file to be run as a CGI script as opposed to being returned as a web page.
The Rewrite directives are needed because we want all requests to be handled by the Woof! CGI handler without having to specify the handler in the request URL. Without these directives, URL's of the form http://www.mysite.com/cgi_server.tcl/... would have to be used to access the Woof! application. The RewriteEngine directive enables URL rewriting. The RewriteRule directive is what channels all URL's to our Woof! CGI server. However, we need to make one exception - images, stylesheets and other static files should be served without going through the additional Woof! overhead. The RewriteCond directive takes care of this situation. It stipulates that the following RewriteRule will only have effect if the requested file name does not exist. Thus requests for files within the public directory tree will be served without Woof! being invoked. For more details on how rewriting works, refer to the Apache documentation.
Step 4 - enabling Apache modules
There are two final steps that may be necessary to complete Apache configuration - enabling the Apache modules for CGI and URL rewriting. In many cases, these modules will already be enabled. If not, make sure the following lines are present and not commented out in the httpd.conf configuration file.
LoadModule cgi_module modules/mod_cgi.so LoadModule rewrite_module modules/mod_rewrite.so
Completing the installation
That completes Apache configuration. You can now move on to completing the installation.