1. Apache httpd should be installed on all the servers with the support of mod_proxy, mod_proxy_http and mod_proxy_balancer modules.
2. Open httpd-vhosts.conf and add the following configurations inside the VirtualHost block. Follow the complete settings below:
<VirtualHost localhost:1000> DocumentRoot C:/wamp/www/loadtest ServerName loadtest ProxyRequests Off <Proxy balancer://web-nodes> BalancerMember http://localhost:1001 route=load1 min=3 max=5 loadfactor=2 BalancerMember http://localhost:1002 route=load2 ProxySet stickysession=NODE </Proxy> ProxyPass /balancer-manager ! ProxyPass / balancer://web-nodes <Location /balancer-manager> SetHandler balancer-manager Order deny,allow Allow from all </Location> </VirtualHost>
Save the httpd-vhosts.conf after making the above settings and restart the server. That will complete our task of creating Apache httpd as reverse proxy load balancer server.
Testing PHP Cluster
Now, to test your PHP load-balance setup, create a file index.php in your application nodes load1 and load2. The source code for the file would be very simple and as below:
For PHP application load1
<?php echo 'Hi, I am from http://localhost:1001'; ?>
For PHP application load2
<?php echo 'Hi, I am from http://localhost:1002'; ?>
After creating these files, try to load these files from your load balancer url i.e. http://localhost:1000/ for multiple times. If your server setup is correct, you can view the output as shown in below screenshots:
Data coming from http://localhost:1001
Data coming from http://localhost:1002
To see, how your load balancer is performing and if you have set it up as explained earlier, you can visit the url http://localhost:1000/balancer-manager and see the output as shown below:
Thats all, to add more application nodes to the load balancer, you only have to configure BalancerMember as configured above with its url.