如何为 PHP 设置私有文件夹包括用于本地测试和实时使用的文件。

发布于 2025-01-02 22:11:50 字数 1545 浏览 1 评论 0原文

这里有点菜鸟。这里可能有一个简单的解决方案 - 但我无法让它工作或创建一个非混乱的测试环境。这个问题可能在其他地方得到了部分答案,但我仍然很困惑——所以我要问。

Linux VPS 上的实时路径(vhosts 目录中有许多站点):

/var/www/vhosts/mysite.com/subdomains/mysubDomain/httpdocs/index.php /* the public, everyone can see web root directory */  

我希望能够配置私有级别,包括文件夹:

/var/www/vhosts/mysite.com/subdomains/mySubdomain/includes/myincludes.php  /*where I want the webserver only to read */  

注意:我还想在上传后使用同级目录来移动私有文件。

在本地,我尝试在以下位置创建类似的结构:

C:\xampp\htdocs\mySubdomain\httpdocs  

一个坏主意是将本地 vHosts 文件中的 DocumentRoot 设置为 mySubdomain 文件夹 - 但这会公开以下目录结构:

<img src=”/httpdocs/images/image.png">  

- 并且在实时站点中是不可接受的。

在我的 XAMPP 测试服务器上,我已经设置了 vhosts 文件,为 mysite.local 创建以下内容

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
     DocumentRoot C:/xampp/htdocs/
    ServerName localhost
</VirtualHost>
<VirtualHost mysite.local>
    DocumentRoot "C:/xampp/htdocs/mySubDomain/httpdocs"
     ServerName mysite.local
     <Directory "C:/xampp/htdocs/mysite" ></Directory>
</VirtualHost>

但是,我无法访问 mySubdomain 文件夹中的包含内容。

问题:

  1. 整个方法是否比“实时”级别文件夹(即 httpdocs/includes)中的 htaccess 提供任何真正的好处?我看到多个参考资料表明“低于公共”的存储将是更安全的文件和首选文件夹结构。
  2. 是包含路径和文档根设置吗?还有其他神奇和微妙的平衡设置吗?如何在 httpdocs(不是 htdocs 本地文件夹被标识为公共目录)的情况下创建本地测试访问?
  3. 奖金(以及新手赠品),如果可以在此配置中设置 DreamweaverCS5.5 以利用它的一些优秀功能(例如自动发现包含文件)以进行测试和浏览器检查。

Bit of a noob here. There is a probably a simple solution here - but I can’t get it to work or create a non-kludgey environment for testing. This may be answered in part elsewhere, but I'm still pulling hair out - so I'm going to ask.

The live path on a Linux VPS (with many sites in vhosts directory):

/var/www/vhosts/mysite.com/subdomains/mysubDomain/httpdocs/index.php /* the public, everyone can see web root directory */  

I want to be able to configure a private level includes file folder:

/var/www/vhosts/mysite.com/subdomains/mySubdomain/includes/myincludes.php  /*where I want the webserver only to read */  

Note: I’d also like to use a same-level directory for moving private files after upload.

Locally, I’ve tried to create a similar structure at:

C:\xampp\htdocs\mySubdomain\httpdocs  

One bad ideas is to set DocumentRoot in a local vHosts file to the mySubdomain folder – but that exposes the directory structure in things like:

<img src=”/httpdocs/images/image.png">  

– and will not be acceptable in the live site.

On my XAMPP testing server, I’ve set up the vhosts file, for mysite.local to create the following

NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
     DocumentRoot C:/xampp/htdocs/
    ServerName localhost
</VirtualHost>
<VirtualHost mysite.local>
    DocumentRoot "C:/xampp/htdocs/mySubDomain/httpdocs"
     ServerName mysite.local
     <Directory "C:/xampp/htdocs/mysite" ></Directory>
</VirtualHost>

But, then I can't access my includes in the the mySubdomain folder.

Questions:

  1. Is this whole approach provide any real benefit over htaccess in ‘live’ level folders (ie httpdocs/includes)? I’ve seen multiple references that storage “below public” will be a more secure file and preferred folder structure.
  2. Is it includepath and the Document Root settings? Some other magic and delicate balance of settings? How does one create local testing access where the httpdocs(not the htdocs local folder is identified as the public directory?
  3. Bonus (and the noob giveaway), if it’s possible to setup DreamweaverCS5.5 in this config for leveraging some of it’s fine features(like auto-discovery of the includes file) for testing and browser checking.

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

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

发布评论

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

评论(1

故事还在继续 2025-01-09 22:11:50
  1. 是的,确实如此。例如,如果某些东西或某人以某种方式搞砸了网络服务器,足以破坏 PHP,但不是网络服务器本身,人们也许可以下载 public/somebusinesslogic.php,但不能下载 private/somefilewithpasswords。 php. .htaccess 文件也可以在 Apache 上禁用,这取决于它的实际内容,可能需要一段时间才能注意到。
  2. 你在任何时候都没有提供错误的内容,所以我不能告诉你出了什么问题,但是在 Windows 上模仿这个设置应该不是问题,只要你使用相关的包含...
  3. 我对产品有足够的仇恨我见过用 DreamWeaver 创建的,然后我不会用十英尺的杆子碰它。当然,这是 5 年前的事了。它可能已经变得不那么可怕了。
  1. Yes, it does. For instance, if somehow something or somebody screws up the webserver enough the break PHP, but not the webserver itself, people maybe able to download public/somebusinesslogic.php, but NOT private/somefilewithpasswords.php. .htaccess files can also be disabled on Apache, which depending on the actual contents of it can take a while to notice.
  2. At no single point did you provide the contents of your errors, so I cannot tell you what goes wrong, but it should not be a problem to mimic this setup on Windows, provided you use relative includes...
  3. I have enough hate for products created with DreamWeaver that I have seen then I wouldn't touch it with a ten foot pole. Granted, this was 5+ years ago. It may have become less awful.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文