使XAMPP/Apache在htdocs文件夹之外提供文件 [英] Make XAMPP / Apache serve file outside of htdocs folder

查看:64
本文介绍了使XAMPP/Apache在htdocs文件夹之外提供文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以配置 xampp 来提供 htdocs 目录?

例如,假设我有一个位于以下位置的文件:

C:\ projects \ transitCalculator \ trunk \ TransitCalculator.php

和我的 xampp 文件通常从以下位置提供:

C:\ xampp \ htdocs \

(因为这是默认配置),有什么方法可以使Apache识别并提供我的 TransitCalculator.php 文件,而无需将其移动到 htdocs 下?最好是,我希望Apache提供/具有对projects目录的全部内容的访问权,并且我不想将project目录移到 htdocs 下.

进行了编辑,将Apache添加到问题标题中,以使问题/答案更易于搜索"

解决方案

好吧,每 pix0r 火花'和戴夫的答案,看来有三种方法可以做到这一点:


虚拟主机

  1. 打开C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf.
  2. 取消注释〜第19行( NameVirtualHost *:80 ).
  3. 添加您的虚拟主机(〜第36行):

     < VirtualHost *:80>DocumentRoot C:\ Projects \ transitCalculator \ trunkServerName transitioncalculator.localhost<目录C:\ Projects \ transitCalculator \ trunk>订单允许,拒绝全部允许</目录></VirtualHost> 

  4. 打开主机文件(C:\ Windows \ System32 \ drivers \ etc \ hosts).

  5. 添加

      127.0.0.1 transitioncalculator.localhost #transitCalculator 

    到文件末尾(在Spybot之前-如果已安装,则搜索并销毁文件).

  6. 保存(您可能必须将其保存到桌面,更改旧主机文件的权限(右键单击>属性),然后将新主机复制到旧主机上的目录中(或重命名旧主机),如果您正在使用Vista并遇到麻烦).
  7. 重新启动Apache.

现在,您可以通过浏览到 http://transitcalculator.localhost/来访问该目录.


创建别名

  1. 从您的 http.conf 文件的第200行开始,在<目录"C:/xampp/htdocs"> </Directory> (〜第232行),然后将其粘贴到下面,并以 C:/xampp/htdocs 替换为所需的目录(在本例中为 C:/Projects)为您的服务器授予新目录的正确权限.

  2. 找到< IfModule alias_module></IfModule> 部分(〜第300行)并添加

     别名/transitCalculator"C:/Projects/transitCalculator/trunk" 

  3. Alias 注释块下方的

    (或与您的需求相关的任何东西).


更改文档根目录

  1. 在C:\ xampp \ apache \ conf \ httpd.conf中编辑〜176行;将 DocumentRoot"C:/xampp/htdocs" 更改为 #DocumentRoot"C:/Projects" (或您想要的任何内容).

  2. 编辑〜203行以匹配您的新位置(在本例中为 C:/Projects ).


注释:

  • 您必须使用正斜杠"/"而不是反斜杠"\".
  • 不要在结尾加上"/".
  • 重新启动服务器.

Is it possible to configure xampp to serve up a file outside of the htdocs directory?

For instance, say I have a file located as follows:

C:\projects\transitCalculator\trunk\TransitCalculator.php

and my xampp files are normally served out from:

C:\xampp\htdocs\

(because that's the default configuration) Is there some way to make Apache recognize and serve up my TransitCalculator.php file without moving it under htdocs? Preferably I'd like Apache to serve up/have access to the entire contents of the projects directory, and I don't want to move the projects directory under htdocs.

edit: edited to add Apache to the question title to make Q/A more "searchable"

解决方案

Ok, per pix0r's, Sparks' and Dave's answers it looks like there are three ways to do this:


Virtual Hosts

  1. Open C:\xampp\apache\conf\extra\httpd-vhosts.conf.
  2. Un-comment ~line 19 (NameVirtualHost *:80).
  3. Add your virtual host (~line 36):

    <VirtualHost *:80>
        DocumentRoot C:\Projects\transitCalculator\trunk
        ServerName transitcalculator.localhost
        <Directory C:\Projects\transitCalculator\trunk>
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    

  4. Open your hosts file (C:\Windows\System32\drivers\etc\hosts).

  5. Add

    127.0.0.1 transitcalculator.localhost #transitCalculator
    

    to the end of the file (before the Spybot - Search & Destroy stuff if you have that installed).

  6. Save (You might have to save it to the desktop, change the permissions on the old hosts file (right click > properties), and copy the new one into the directory over the old one (or rename the old one) if you are using Vista and have trouble).
  7. Restart Apache.

Now you can access that directory by browsing to http://transitcalculator.localhost/.


Make an Alias

  1. Starting ~line 200 of your http.conf file, copy everything between <Directory "C:/xampp/htdocs"> and </Directory> (~line 232) and paste it immediately below with C:/xampp/htdocs replaced with your desired directory (in this case C:/Projects) to give your server the correct permissions for the new directory.

  2. Find the <IfModule alias_module></IfModule> section (~line 300) and add

    Alias /transitCalculator "C:/Projects/transitCalculator/trunk"
    

    (or whatever is relevant to your desires) below the Alias comment block, inside the module tags.


Change your document root

  1. Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change DocumentRoot "C:/xampp/htdocs" to #DocumentRoot "C:/Projects" (or whatever you want).

  2. Edit ~line 203 to match your new location (in this case C:/Projects).


Notes:

  • You have to use forward slashes "/" instead of back slashes "\".
  • Don't include the trailing "/" at the end.
  • restart your server.

这篇关于使XAMPP/Apache在htdocs文件夹之外提供文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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