PHP 项目的 /var/www/ 文件夹结构

发布于 2024-07-16 16:39:04 字数 264 浏览 2 评论 0原文

我仅将 MAMP 用于我的开发环境,并没有真正理解 Web 服务器上 /var/www/project-name/ 的文件夹结构。 我想知道您是否打算将 Web 服务器指向 htdocs 文件夹,或者应该指向项目文件夹的根目录?

我问的原因是因为出于安全目的,库应该存在于 htdocs 文件夹之外,但它们是如何从 Web 应用程序本身指向的? 如果 Web 服务器指向 Web 应用程序的 htdocs 文件夹,那么 Web 应用程序肯定无法访问 htdocs 文件夹之外的文件夹吗?

I'm using MAMP just for my development environment and haven't really understood the folder structure of /var/www/project-name/ on a web server. I'm wondering whether you're meant to point the web server to the htdocs folder or it's supposed to point to the root of the project folder?

The reason I ask is because libraries are meant to exist outside of the htdocs folder for security purposes, but how are they pointed to from the web application itself? Surely the web application can't access folders outside of the htdocs folder if the web server is pointing to the htdocs folder for the web application?

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

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

发布评论

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

评论(5

爱你不解释 2024-07-23 16:39:04

一个简单的解决方案是采用如下所示的文件夹结构:

/var/www/project-name/
    + webroot/
    + libraries/

将 apache2 DocumentRoot 指向 webroot 目录。 将您不希望从网络访问的所有库保留在 libraries 目录中。 在您的 php 代码中,使用 include 指令来访问库代码。

诀窍是要了解 php 可以包含系统上它具有读取权限的任何文件。 浏览您网站的人只能访问您的 webroot 目录中的文件。

A simple solution is to have a folder structure like so:

/var/www/project-name/
    + webroot/
    + libraries/

Point your apache2 DocumentRoot to the webroot directory. Keep all the libraries that you don't want accessible from the web in the libraries directory. In your php code, use the include directive to access the libraries code.

The trick is to understand that php can include any file on your system it has read access to. A person browsing your website can only access files inside your webroot directory.

伤痕我心 2024-07-23 16:39:04

如果同一服务器上有多个虚拟主机,则通常将每个站点都放在 /var/www 下的目录中,并且每个站点都有一个 htdocs 文件夹,其中被安装为 Web 根目录。 然后,您可以将日志和特定于应用程序的库放在 Web 根目录上方的文件夹中。 例如。:

/var/www/lolcats.com
/var/www/lolcats.com/htdocs
/var/www/lolcats.com/htdocs/index.php
/var/www/lolcats.com/lib
/var/www/lolcats.com/log

If you have multiple vhosts on the same server, it's pretty common to have each site in a directory under /var/www, and each of these have a htdocs folder, which is mounted as the web root. You can then have logs and application-specific libraries in a folder above the web root. Eg.:

/var/www/lolcats.com
/var/www/lolcats.com/htdocs
/var/www/lolcats.com/htdocs/index.php
/var/www/lolcats.com/lib
/var/www/lolcats.com/log
倥絔 2024-07-23 16:39:04

PHP 可以访问文件系统中 apache 服务器用户具有正确权限的任何文件。 在运行没有虚拟主机的 apache 的 Linux 机器上,/var/www 是 htdocs 目录的常用位置。

PHP can access any file in the filesystem for which the apache server user has the correct permissions. On a linux box running apache without virtual hosts, /var/www is a common place to use for your htdocs directory.

昵称有卵用 2024-07-23 16:39:04

您将库放置在 PHP 的 include_path,一般用户无法访问。

You place the libraries in PHP's include_path which is inaccessible to the general user.

泡沫很甜 2024-07-23 16:39:04

以与域工作相同的方式将本地网站映射到目录中是一个好主意。

通常,您在一个网络托管帐户上有多个网站,因此设置虚拟主机来镜像设置。

如果您的共享主机是:

/var/www/root
 /var/www/root/website1
 /var/www/root/website2
 /var/www/root/website3

在本地 PC 上创建 3 个虚拟主机,但保持相同的文件结构。

此外,根据服务器文件结构,使用配置文件中的条件来设置不同的站点,以确保相同的配置文件适用于两种设置。 这意味着您可以保留一步构建过程。

It is a googd idea to map your local websites in directories in the same way as your domains work.

Often you have multiple websites on a single web hosting account, so setup virtual hosts to mirror the setup.

If your shared hosting is:

/var/www/root
 /var/www/root/website1
 /var/www/root/website2
 /var/www/root/website3

Create 3 vitual hosts on your local PC but keep an identical file structure.

Also, use conditions in your config files to setup the site deifferently depending on the server file structure, to ensure the same config file works on both setups. This means you keep your one-step build process.

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