Join 3,553 readers in helping fund MetaFilter (Hide)


Run multiple php websites from a single server?
July 16, 2008 11:04 AM   Subscribe

How practical is it to run multiple php websites on multiple servers from a single script on one central server?

I wrote a script which is now being used on a few websites, and it has been suggested that to make updates simpler we run it from a central server ie each website will use the script from one source to actually run. While on the surface this seems like A Very Good Ideas, I am sure there are issues which might make it a very bad idea. Can you convince me one way or the other.
posted by zingzangzung to Computers & Internet (8 answers total)
Expand on "run." Do you mean download the source from a central website and serve it normally, do something potentially crazy like include()ing a remote file or something client-side like an iframe?

Or something totally different?
posted by Skorgu at 11:13 AM on July 16, 2008

I think we need more information regarding expected traffic/load on server and what the script is actually doing (file writing? database connection? generating images?)...
posted by rlef98 at 11:13 AM on July 16, 2008

I mean download from a central server and serve normally. There will be database connections but I don't think the server load will a big issue. It's an ecommerce/shopping cart script where the websites run essentially the same shop (one database) embedded in different websites.
posted by zingzangzung at 11:18 AM on July 16, 2008

What do you mean by "use the script from one source to actually run?"

Typically what you're talking about is handled by keeping the one copy in a version control facility such as Subversion, then checking out the latest version whenever the servers should be updated. Think in terms of "releasing" or "publishing."

On the other hand, it may just be that you could run all of the sites from one server, with virtual hosts for each of the domains all pointing to (and serving from) the same directory.
posted by rhizome at 11:25 AM on July 16, 2008

Yeah I know about version control, the idea here is like your second para Rhizome ie run all of the sites from one server
posted by zingzangzung at 11:30 AM on July 16, 2008

So you're doing something like centrally transferring the source .php file(s) from server1 to store1, store2, store3, etc. and those stores run it like any other php file(s)? I don't know what you mean by database connections, unless you're rewriting the source for each client.

Possible problems: how are you transporting the source? You'll need SSL if you're going to serve the script from a web server, and be sure to actually verify the certificate on the client side, don't use curl -k or something. How often will you pull a new version?

Source control is the answer, just as rhizome says. I'd immediately suggest git because I've been using it and it's awesome. SVN is sort of a bear, but it does work fine.
posted by Skorgu at 11:34 AM on July 16, 2008

If your sites are all on the same server then it's just a matter of pointing all the virtual hosts at the same files and making sure the application works off the host header to know which site is being requested and respond accordingly. It's a sensible way to run lots of sites from a single codebase, and shouldn't require particularly advanced sysadmin and coding skills.
posted by malevolent at 1:39 PM on July 16, 2008

Issues that make reusing a piece of code bad:
- the piece of code requires some kind of setup or pre-configuration by a site prior to use
- the piece of code doesn't handle errors well if the setup isn't done, or if its called incorrectly.
- the piece of code depends on a certain 'state' for it to be executed
- the piece of code passes back a return that the caller might not expect
- the piece of code has unintended side effects on the state of the session or other objects with which it interacts.

Its very practical to reuse code across multiple sites. Gallery does it, MovableType does it, and its essentially the core of a Service Oriented Architecture. You've got to really think hard about what your service/script provides, what consumers of your service will need and set their expectations on how to use your service/script. That and test the snot out of it.
posted by TuffAustin at 2:08 PM on July 16, 2008

« Older Found an old W-2 from the chao...   |  What kind of work is being don... Newer »
This thread is closed to new comments.