2

I am trying to create a rather complex setup using a combination of lighttpd, some custom Ruby proxies, rails/ramaze (running on Thin), and PHP. Currently it is setup like this:

  1. A browser issues the request which hits the lighttpd frontend. lighttpd is setup with mod_proxy to route this request into one of many Ruby proxies that have been custom designed by me.

    proxy.balance = "fair"
    proxy.server = ( "" =>
            (
                    ( "host" => "127.0.0.1", "port" => 9090 ),
                    ( "host" => "127.0.0.1", "port" => 9091 )
            )
    )
    
  2. The request is forwarded into one of the Ruby processes, which then opens up a new connection to one of many thin instances running an application. It uses some load balancing magic along with a cluster of networked servers.

  3. The thin instance generates the page, sends it back to the proxy, and the proxy sends the page back to lighttpd which serves it to the browser.

My question is, given the above architecture, what would be the best way to add PHP support into this cluster? PHP needs to be running behind the Ruby proxy, so that I can differentiate between PHP and Ruby requests and route them to the proper location, but I cannot find a thin-like server for PHP. Should I manually launch php-cgi on the cluster, then add FCGI support to my Ruby proxy? Or should I launch a new lighttpd instance on every server specifically to generate PHP pages (I feel this would be closest to my thin model with Ruby, but am worried about overhead and the lack of control this gives me)?

Keep in mind that every application needs to be jailed into it's own *nix account, with some applications taking up 10+ accounts across several servers. I also need a way to properly limit the amount of server resources that the PHP application uses (perhaps by only launching one or two php-cgi instances per *nix acount?).

1 Answers1

0

You probably want php-fpm.

On recent Ubuntu versions: apt-get install php5-fpm.

After installation, you should have a default configuration available – if it isn't running already: /etc/init.d/php5-fpm start.

php-fpm will start PHP processes for you. If you have multiple sites, consider using different pools of workers. The configuration should be in /etc/php/php-fpm.d (or similar). Check your /etc/php5/fpm.conf for an include directive. Multiple pools allow you to seperate applications, e.g. scale out differently.

Once the processes are running, they will listen on a localhost:port or a unix-domain socket. I'm guessing the default is TCP.

Then configuration in lighttpd should be very similar to your configuration for thin.

Let me know if this helps, or if you need further pointers!

Till
  • 1,019
  • 6
  • 14