views:

38

answers:

3

This is something I've never seen done, and I'm not turning up in my research, but my boss is interested in the idea. We are looking at some load balancing options, and wonder if it is possible to have apache and php installed on multiple servers, managed by a load balancer, but have all the actual php code on one server, with the various apache servers pointing to the one central code base?

+4  A: 

For instance NFS mounts are certainly possible, but I wouldn't recommend it. A lot of the advantage of loadbalancing is lost, and you're reintroducing a single point of failure. When syncing code, and rsync cronjob can handle itself very nicely, or a manual rsync on deployment can be done.

What is the reason you would want this central code base? I'm about 99% sure there is a better solution then a single server dishing out code.

Wrikken
or even a checkout from the version control system. And NFS is certainly not the only alternative for a networked filesystem to consider.
Vinko Vrsalovic
You're right, an NFS share was only an example.
Wrikken
A: 

I believe it is possible. To add to Wrikken's answer, I can imagine NFS could be a good choice. However, there are some drawbacks and caveats. For one, when Apache tries access files on an NFS share that has gone away (connection dropped, host failed, etc) very bad things happen. Apache locks up, and continues to try to retrieve the file. The processes attempting to access the share, for whatever reason, do not die, and it is necessary to re-boot the server.

If you do wind up doing this, I would recommend an opcode cache, such as APC. APC will cache the pre-processed php locally, and eliminate round trips to your storage. Just be prepared to clear the opcode cache whenever you update your application/

Chris Henry
In my experience, APC is a nice cache to have, but checks file for modtimes, so does not need clearing when updating files, and equally fails if the files aren't there. Or did I miss some APC settings?
Wrikken
Sure did, apc.stat, which is set to 1 by default, and not included in the default apc.ini file. If set to 0, APC will not check the updated on date of php files, and keep the pre-processed version until the opcode cache is cleared. The performance increase with a setting of 0 is pretty huge, btw.
Chris Henry
A: 

PHP has to run under something to act as a web processor, Apache is the most popular. I've done NFS mounts across servers without problem. Chances are if NFS is down, the network is down. But it doesn't take long to do an rsync across servers to replicate files, and is really a better idea.

I'm not sure what your content is like, but you can separate static files like javascript, css and images so they are on their own server. lighttpd is a good, light weight web server for things like this. Then you end up with a "dedicated" php server. You don't even need a load balancer for this setup.

Keep in mind that PHP stores sessions on the local file system. So if you are using sessions, you need to make sure users always return to the same server. Otherwise you need to do something like store sessions in memcache.

Brent Baisley