How to access files outside the DocumentRoot in a VirtualHost in XAMPP?

守給你的承諾、 提交于 2019-12-25 16:59:13

问题


I have a Virtual Host configured in Windows 7. The project is located in C:\project with the following structure:

project
  \cache
  \configs
  \htdocs
    \css
    \images
    \js
    \.htaccess
    \index.php
  \includes
    \setup.php
    \en.php
  \lib
  \templates
  \templates_c

In my httpd-vhosts.conf, I created a VirtualHost:

 <VirtualHost *:80>
    DocumentRoot "C:/project/htdocs"
    ServerName project.dev

    <Directory "C:/project/htdocs">
        Options Indexes FollowSymLinks ExecCGI Includes
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

And added 127.0.0.1 project.dev to the C:\Windows\System32\drivers\etc\hosts.

The problem is that I want the htdocs to be the directory from which httpd will serve files but I want to include, with PHP, files, for example, located in the includes directory.

How can I solve this problem? I already tried so many solutions from $_SERVER['DOCUMENT_ROOT'] to Apache Alias and .htaccess tweaking but none have worked so far. There must have be some easy solution. Maybe I'm not understanding quite correctly the concept of DocumentRoot. I just want to emulate the typical server folder public_html/www/htdocs while keeping important files out of the browser/user scope.


回答1:


This is a VHost I took from my httpd-vhosts.conf. The only extra configuration I made was to get around the 403 I was hitting:

<VirtualHost *:80>
    ServerName "Markdown.loc"
    ServerAlias "www.Markdown.loc"
    DocumentRoot "C:\INTERNAL\PHP\Markdown"
    <Directory "C:\INTERNAL\PHP\Markdown">
        Options +Indexes
        AllowOverride All
    </Directory>
</VirtualHost>

All my other VHosts look like this:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/somesite.loc"
    ServerName somesite.loc
    ServerAlias www.somesite.loc
</VirtualHost>

If you're simply looking to include something from a dir on the same level as your htdocs though, include("../includes/somefile.php") should work just fine.

If I've got your problem wrong, let me know, and I'll try to help you more.




回答2:


Set your include path within your virtualhost or .htaccess:

php_value include_path ".;c:/project"


来源:https://stackoverflow.com/questions/15182008/how-to-access-files-outside-the-documentroot-in-a-virtualhost-in-xampp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!