如何使用PHP的相同代码库在同一服务器上运行多个网站? [英] How do I run multiple websites on the same server with the same code base in PHP?

查看:75
本文介绍了如何使用PHP的相同代码库在同一服务器上运行多个网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义的专业CMS,其中包含许多客户端,每个客户端都有自己的域名,网站,管理区域和数据库,但是所有客户端都位于同一台服务器上。

I have created a custom, specialized CMS with a number of clients on it, each with their own domain name, website, admin area and database, but all residing on the same server.

每当我有一个新客户端时,我只需复制所有代码,在配置文件中更改3行,然后取出所有样式/数据数据库或从他们从自己的管理区域发布到服务器的上载文件。

Whenever I get a new client, I simply copy all of the code over, change 3 lines in a config file, and then all of their styles/data is taken out of the database or from uploads they post to the server from their own admin area.

听起来不错吗?

嗯,最近我决定更新所有客户端站点时,这成了一个主要的难题。显然,我必须在每次安装时更改代码。对于主要更新,这很好,但是对于频繁的调整等而言,重复上载的工作变得非常烦人。...我希望有一天有数十个或数百个客户端,因此最终必须将代码集中化,以便在一处更改它会在任何地方更新它。。。

Well when I recently decided to update all of the clients sites, this became a major pain. Obviously i had to change the code on each install. For a major update this is fine, but for frequent tweaks or the like, duplicating the effort of uploading becomes very annoying....I hope to someday have dozens or hundreds of clients, so the code will eventually have to be centralized so that changing it in one place updates it everywhere...how does one do that?

推荐答案

一个简单的解决方案是将子目录中的源代码(文件除外),子目录中的文件应针对每个客户端进行更改(例如,配置文件)。

A easy solution would be to put the source code in a subdirectory, except the files, which should be altered for each client (for example, the config file).

然后您可以将此源代码目录放在某个位置

You can then put this source code directory somewhere out and just create symlinks to it.

例如,您的目录结构可能类似于:

For example, your directory structure might look like:

/var/www/src/index.php
/var/www/src/more_source.php
/var/www/clients/client_a/settings.php
/var/www/clients/client_a/src -> ../../src/
/var/www/clients/client_b/settings.php
/var/www/clients/client_b/src -> ../../src/

如果选择此结构,则只需要更改,将是settings.php的包含内容(例如,从要求 settings.php 要求 ../settings.php)。

If you choose this structure, the only thing you would need to change, would be the include for settings.php (e.g. from require "settings.php" to require "../settings.php").

这篇关于如何使用PHP的相同代码库在同一服务器上运行多个网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆