-1

What is the best scalable architecture for an Apache/PHP environment? I would like to use a single Apache instance and offload requests to N web application (PHP) servers; how is this typically accomplished?

emsworth
  • 101
  • 4

2 Answers2

1

I am using fastcgi and php-fpm, this way you can have multiple php-fpm daemons on different machines.

Bear in mind that php-fpm needs to have access to your docroot, so some kind of shared storage will be necessary when using multiple machines.

Niko S P
  • 1,182
  • 8
  • 16
  • This is exactly what I was looking for, thanks. I also liked the solution by @daveadams, but I believe that requires a web server on each backend machine. – emsworth Feb 14 '12 at 17:27
1

There are a wide variety of solutions to this problem, but if you're already familiar with Apache, then the simplest solution will be to make sure mod_proxy_http and mod_proxy_balancer are enabled on your Apache build:

$ [...]/httpd -t -D DUMP_MODULES |grep proxy

Then refer to the mod_proxy and mod_proxy_balancer documentation, but you are probably wanting to do something like this:

ProxyRequests Off
<Proxy balancer://myphpapp>
  BalancerMember http://server1.backend.php:8000
  BalancerMember http://server2.backend.php:8000
</Proxy>
ProxyPass / balancer://myphpapp/
ProxyPassReverse / balancer://myphpapp/

(The ProxyRequests Off looks weird, but that's to turn forward proxying off, because this setup will be reverse proxy. If you are using SSL, you may also need to add SSLProxyEngine On to keep things flowing.)

That's just the first step, of course. It will round-robin requests between the members of the balancer set you defined. If you want sticky sessions, load ratios, filtering based on user agent, cookies, or IP address, etc, check the documentation linked and of course, please post more questions.

daveadams
  • 1,279
  • 6
  • 12