PHP核心代码目录结构

发布于 2024-11-01 03:48:00 字数 462 浏览 5 评论 0原文

我希望集中许多 Web 应用程序代码,以便多个组件可以访问相同的核心功能。这就是我设置网站的方式:

/var/www/website - domain.com
/var/www/subdomain1 - subdomain1.domain.com
/var/www/subdomain2 - subdomain2.domain.com

当然,当涉及到公共功能的重复时,我遇到了很多麻烦,因为对一个区域所做的任何更改也需要应用于其他区域地区。我建议的解决方案是在 /var/www 中创建一个新目录,其中将包含所有核心脚本:

/var/www/code - 核心代码

然后我将设置PHP 包含目录到 /var/www/code,因此脚本可以包含这些文件而无需指定绝对路径。

你能想到任何更有效的方式来集中代码吗?

非常感谢!

I'm looking to centralize a lot of my web applications code, so that multiple components have access to the same core functionality. This is how I have the website set up:

/var/www/website - domain.com
/var/www/subdomain1 - subdomain1.domain.com
/var/www/subdomain2 - subdomain2.domain.com

Naturally I've had a lot of trouble when it comes to the duplication of common functionality, as any changes made to one area would also need to be applied to other areas. My proposed solution is to create a new directory in /var/www which will contain all of the core scripts:

/var/www/code - core code

I would then set the PHP include directory to /var/www/code, so scripts can include these files without having to specify the absolute path.

Can you think of any more efficient ways of centralizing the code code?

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮云落日 2024-11-08 03:48:00

对于这个目的,你的方法已经足够好了。

小建议:
将前端脚本存储在 /var/www/website/www 等目录中,而不是 /var/www/website 中。将会有索引文件、ajax 处理器和类似的脚本。但是基于项目的包含内容(以及其他杂项)将存储在 /var/www/website/includes 等目录中。这是简单而有效的防御黑客攻击您的包含文件的方法

,因此您的文档根目录将位于 /var/www/website/www (域)和 /var/www/website/subdomain/www/ (子域)

Your approach is good enough for this purpose.

Little suggestion:
store your front-end scripts in directory like /var/www/website/www instead of /var/www/website. There will be index file and ajax processors and scripts like that. But your project-based inclusions (as well as other miscellaneous stuff) would be stored in directory like /var/www/website/includes. It is simple yet efficient defense from hacker attacks on your inclusion files

so, your document roots will be in /var/www/website/www (domain) and /var/www/website/subdomain/www/ (subdomain)

太傻旳人生 2024-11-08 03:48:00

看来您的想法是正确的:

在多个 PHP 站点之间共享代码

It seems that you are thinking correctly :

Share Code between multiple PHP sites

瘫痪情歌 2024-11-08 03:48:00

这只是一个建议,但您应该将公共内容放在 /var/www/* 中,这可能最终会被公开访问(由于您的 http 服务器或由于某些配置错误),并创建一些其他内容共享代码/库的目录,例如 /usr/local/lib/php/*

为了提高安全性,您应该使用 open_basedir 添加私有和公共目录以及上传和会话目录来构建它。

并且不要忘记对您的库进行版本控制,例如:

/usr/local/lib/php/myLib-1.0
/usr/local/lib/php/myLib-1.2

等。

因此,您将能够在不破坏所有内容的情况下进行更改。

It's only a suggestion, but you should put the public content in the /var/www/* which may end being publicly accessible—either because of your http server or because of some misconfiguration—and create some other directories for your shared code/libs like /usr/local/lib/php/*.

For more security you should frame it with open_basedir adding the private and public dirs—as well as upload and session dirs.

And don't forget to version your libs, e.g.:

/usr/local/lib/php/myLib-1.0
/usr/local/lib/php/myLib-1.2

etc.

Thus, you'll be able to make changes without breaking everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文