PHP/FastCGI
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

IDE's
Scottit
Groovy
PHP
Code Libraries
EJB Servers
JMS
JCA Resources
JMX
SSL Accelerators
Groovy
Third-party
Code Libraries

PHP scripts can run with Resin using FastCGI. This page explains how to configure Resin and PHP.

  1. Overview
  2. Configuring FastCGIServlet
  3. Configure/build PHP for FastCGI
    1. Compiling PHP with FastCGI
  4. Starting PHP with FastCGI
  5. A Test Page

Overview

Resin works with PHP using the FastCGI protocol through the FastCGIServlet. PHP runs as a separate process waiting for Resin requests.

Configuring Resin with PHP requires the following:

  • Configure Resin's FastCGIServlet to dispatch php requests.
  • Configure/build PHP to enable FastCGI
  • Start PHP as a separate process to listen for Resin's requests.

Configuring FastCGIServlet

The FastCGI servlet requires a single parameter: "server-address" which specifies the FastCGI host and port for PHP. This address must match the port PHP is listening to.

web.xml
<web-xml>
  <servlet servlet-name="php"
           servlet-class="com.caucho.servlets.FastCGIServlet">
    <init>
      <server-address>localhost:8002</server-address>
    </init>
  </servlet>

  <servlet-mapping url-pattern="*.php" servlet-name="php"/>
</web-xml>

Configure/build PHP for FastCGI

PHP must be compiled with FastCGI support. To check whether your PHP has FastCGI, use "php -v". If you see "(cgi-fcgi)", then your PHP already has FastCGI built in. If you only see "(cgi)", you'll need to rebuild PHP.

resin> php -v
PHP 4.3.6 (cgi-fcgi) (built: May  5 2004 12:10:24) (DEBUG)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

Compiling PHP with FastCGI

To compile PHP with FastCGI, you'll add the --enable-fastcgi argument to the PHP ./configure script.

php> ./configure --enable-fastcgi
...
php> make
php> make install
php> php -v
PHP 4.3.6 (cgi-fcgi) (built: May  5 2004 12:10:24) (DEBUG)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

Starting PHP with FastCGI

To start PHP listening for FastCGI requests, add a "-b 8002" argument.

php> php -b 8002

PHP will start, listening for the next request.

A Test Page

Now, add a test.php to your document tree, and browse the location. You should see the result of the PHP page.

test.php
Hello: <?= 1 + 1 ?>

If you have trouble, enable Resin's logging to see what's going on.

<web-app>
  <log name="com.caucho.servlets.FastCGIServlet" level="finer"/>

  ...
</web-app>


Groovy
Third-party
Code Libraries
Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.