Web Server: Using FastCGIProxy to Reverse Proxy to Native PHP

From Resin 4.0 Wiki

(Difference between revisions)
Jump to: navigation, search
Line 22: Line 22:
   <resin:FastCgiProxy regexp="\.php">
   <resin:FastCgiProxy regexp="\.php">

Revision as of 00:00, 6 February 2012


This cookbook will show you how to execute local CGI scripts through Resin using FastCGI. We'll use php-fpm as the FastCGI process manager and map *.php to Resin's included FastCGI servlet. Finally, it will provide instruction on setting up WordPress to run in Resin using FastCGI.

For standard CGI, see Application Server: Native PHP With CGIServlet.

Executing PHP with FastCGI

Setup of FastCGI is sightly more complex than basic CGI, since you need to install php-fpm. php-fpm is PHP's FastCGI process manager. It DOES NOT come with PHP by default. It must be enabled as a compile time option using the flag "--enable-fpm". See PHP-FPM Install documentation for more information. (The IUS Community Project has a php-fpm RPM available.)

# Startup php-fpm

php-fpm will startup by default listening on the local address on port 9000, which works fine for us.

The example below demonstrates how to configure Resin to execute PHP via FastCGI. Keep in bind that Resin comes with [Quercus], Caucho's 100% Java implementation of PHP5. You may not need native PHP if Quercus works for your application.


<web-app xmlns="http://caucho.com/ns/resin"
 <resin:FastCgiProxy regexp="\.php">


Create a simple test php file in your webapp's root directory, as follows:


<?php phpinfo(); ?>

And then access the URL and you will see something like this:


Notice "Server API" shows "FPM/FastCGI".

(As an interesting exercise, try commenting out the <resin:FastCgiProxy> in resin-web.xml, and access the page again. It should still work, but the page now show the Quercus PHP info display instead:)


All *.php is mapped to QuercusServlet by default in app-default.xml. Your resin-web.xml overrides this mapping, but the webapp will fallback to QuercusServlet if not set.

WordPress on Resin with FastCGI and php-fpm

These instructions were tested with Resin 4.0.25 Professional, PHP 5.3.10, and WordPress 3.3.1.

# Before starting, create an empty mysql database for your WordPress tables
# PHP requires the php-mysql extension
# WordPress requires sendmail

# Startup php-fpm

# Shutdown resin 
resinctl stop

# Backup the packaged ROOT webapp directory: 
cd /var/www/webapps 
mv ROOT ROOT.bak

# Download and extract Wordpress:
wget http://wordpress.org/latest.zip
unzip latest.zip

# Rename wordpress to ROOT so that it is served as the ROOT webapp (/ context)
mv wordpress ROOT

# Create resin-web.xml
mkdir WEB-INF
vi WEB-INF/resin-web.xml (copy/paste from the example above)

# Configure WordPress
cp wp-config-sample.php wp-config.php
vi wp-config.php (modify DB_NAME, DB_USER, DB_PASSWORD, DB_HOST)

# Startup Resin
resinctl start

Access the URL :


Personal tools