Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.