Resin and WebDav


Hosting a CGI without Apache

So you've been able to convince your management that the internal Resin Web server can be used just as efficiently an external Web server. Now the problem becomes, How do you handle the various PHP, Perl, and Python applications currently floating around your production Web server? While one answer might be to rewrite them as servlets, that may not be the most efficient approach. The next best thing is to find a way to handle all those various page types as well. The CGIServlet and FastCGIServlet external interpreters let you handle page requests and pass them to an appropriate interpreter. In this section, we show you how to incorporate these interpreters with the internal Resin Web server.

CGIServlet

The Resin internal Web server lets you use external interpreters to handle various languages—Perl, for example. A servlet called com.caucho.http. servlet. CGIServlet is used to pass the Common Gateway Interface (CGI) to the environment for processing. The idea is to "execute" the file in the URL request. The first line of the file specifies the application responsible for executing the contents of the file. For example, consider the following Perl script:

 #!/usr/local/perl use CGI qw(:standard); print header(); print "<html>\n<head>\n",     "<title>Hello!</title>\n",     "</head>\n",     "<body>\n\n";  print "\n</body>\n", "</html>\n"; 

This script tells us that Perl should be used to process the file. We can do the same thing within Resin's internal Web server by placing the following <web-app> element within the configuration file:

 <web-app>   <servlet-mapping url-pattern='*.cgi'         servlet-name='com.caucho.servlets.CGIServlet'/> </web-app> 

This new configuration code tells the Resin that when it finds a URL with a page extension of .cgi it should pass the request to the CGIServlet for processing. This servlet in turn "executes" the page against the system's environment. You can easily change the CGI pattern to PL (for Perl) or some other execution.

FastCGIServlet

Look in the /bin directory of your Unix Resin installation and you will find a Perl script called fastcgirunner.pl. This script is designed to be used in conjunction with the Resin internal Web server and a servlet called com.cau-cho.http.servlet/ FastCGIServlet to allow the execution of server-side CGI code. You can use these components to enable your Resin internal Web server to execute foreign CGI code like PHP.

As an example, let's assume that you want to use Resin as well as PHP. Follow these steps:

  • Step 1—Obtain the source code version of PHP from www.php.net.

  • Step 2—Using the directions in the distributable or the PHP Web site, www.php.net/manual/en/install.commandline.php, compile a CGI or command-line version of PHP. Be sure to use the —fastcgi option when compiling PHP.

  • Step 3—Set your system path so that the PHP executable can be executed by the user your Resin server executes. This might still be root in a development environment or something like "resin".

  • Step 4—Add the following <servlet-mapping> element to the Resin configuration file:

     <web-app>   <servlet-mapping     url-pattern='*.php'     servlet-name='com.caucho.servlets.FastCGIServlet'>     <init-param server-address='localhost:7000'/>   </servlet-mapping> </web-app> 

This <servlet-mapping> tells Resin that if it finds any requests from a client with a page extension of .php, the request should be handled by a servlet called FastCGIServlet. The element tells Resin to redirect the request to port 7000. Of course, you need something on port 7000—and that's the next step.

  • Step 5—Once Resin is running, open a terminal window and change to the /bin directory of the Resin installation. Execute the fastcgirunner.pl Perl script in the following fashion:

     ./fastcgirunner.pl —port 7000 php 

    This command tells the script to execute and listen on port 7000. When a request comes from port 7000, the script should start and pass the request to the .php executable.

  • Step 6—Write a PHP script to test the system. Here's an example:

     #!/usr/local/php <?php phpinfo(); ?> 

When writing PHP scripts for the PHP command-line interpreter, be sure to start the script with the path to the PHP installation.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net