Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently deploying some PHP Zend applications on my servers and this is currently what I got.

1st Layer - Load-balancer + Http-cache.

2nd Layer - web-server (will have many more webservers in here, that's why the load-balancer).

3rd Layer - MySql (will have replication, slave-master, maybe sharding per customer or group of customers).

The question is this, currently Im running nginx + php-fpm on the webserver, all the php code stays in the user respective home folder. When the time passes I'll want to increase the number of servers, php-fpm and nginx instances.

Where should I put the php, because I can't duplicate it among the servers, otherwise updates will screw up consistency ;)

I'm thinking maybe a NFS that will hold all php code and the servers will just point to that.

What the correct approach here?

I'm kind of new to server architecture.

Appreciate your help.

[]'s Rodrigo

share|improve this question
up vote 2 down vote accepted

You really shouldn't put it on NFS. That will make your NFS server a single point of failure. If your NFS is unreachable (maybe it crashes, maybe there's a network problem..), then your whole site is offline.

Instead, store your PHP in some central location - anywhere. It doesn't matter where. Then when you need to push your files to a new server, just copy then to the new server.

You will have to make sure your users do not update the PHP on the web servers directly. They should update them in the central location.

For example, let's say you have web1 and web2 as your web servers, and your PHP files are kept in /home/foo/php and /home/bar/php. This is currently your authoritative location and probably needs to change.
Set up something like /var/code/foo/php and /var/code/bar/php, and tell your users to update there. When they do an update, run a script which copies the files to /home/foo/php and /home/bar/php` on each web server.

Part of the difficulty you're having now, and will continue to have, is that you're storing data in users home directories.
You should consider moving to a proper version control system like Mercurial, Git or SVN. Store all of the data in the same location, and then check out those wherever you want.

An example of this:
Use a server (let's call it dev1) and install SVN. Create an new project in SVN (let's call it php_project1). Tell your users to check out svn://dev1/php_project1/userN, and to edit and commit the files to SVN.
Then on your web servers, you can do something like:

cd /home/user1/php
svn checkout svn://dev1/php_project1/user1

And any time you need to update your web servers, you just run svn update in the home directory.

There's a lot more I could go in to. Welcome to managing a web farm.

share|improve this answer
  • 1st Layer - only load-balancer
  • 2nd Layer - static/image/video web-server(nginx); common web-server(nginx+php-fpm); script server(nginx+php-fpm or cpp; run "heavy" script); memcached server
  • 3rd Layer - sharding master-slave MySQL server

and monitoring(Zabbix) and mail server. Pinba realtime monitoring/statistics server for PHP using MySQL.

I'm thinking maybe a NFS that will hold all php code and the servers will just point to that.

bad idea, use Version Control System(git,svn,mercurial,...) and deployment script

share|improve this answer
Thanks for your answer, but how do I do when I get to the point that I need a second nginx server, serving the same code? the second nginx server will probably be in a different server, where does the php code goes? – Rodrigo Dellacqua Jan 23 '11 at 19:44

Your Answer


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.