使XAMPP/Apache在htdocs文件夹之外提供文件 [英] Make XAMPP / Apache serve file outside of htdocs folder
问题描述
是否可以配置 xampp 来提供 htdocs
目录?
例如,假设我有一个位于以下位置的文件:
C:\ projects \ transitCalculator \ trunk \ TransitCalculator.php
和我的 xampp 文件通常从以下位置提供:
C:\ xampp \ htdocs \
(因为这是默认配置),有什么方法可以使Apache识别并提供我的 TransitCalculator.php
文件,而无需将其移动到 htdocs
下?最好是,我希望Apache提供/具有对projects目录的全部内容的访问权,并且我不想将project目录移到 htdocs
下.
进行了编辑,将Apache添加到问题标题中,以使问题/答案更易于搜索"
好吧,每 pix0r 的火花'和戴夫的答案,看来有三种方法可以做到这一点:
虚拟主机
- 打开C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf.
- 取消注释〜第19行(
NameVirtualHost *:80
). -
添加您的虚拟主机(〜第36行):
< VirtualHost *:80>DocumentRoot C:\ Projects \ transitCalculator \ trunkServerName transitioncalculator.localhost<目录C:\ Projects \ transitCalculator \ trunk>订单允许,拒绝全部允许</目录></VirtualHost>
-
打开主机文件(C:\ Windows \ System32 \ drivers \ etc \ hosts).
-
添加
127.0.0.1 transitioncalculator.localhost #transitCalculator
到文件末尾(在Spybot之前-如果已安装,则搜索并销毁文件).
- 保存(您可能必须将其保存到桌面,更改旧主机文件的权限(右键单击>属性),然后将新主机复制到旧主机上的目录中(或重命名旧主机),如果您正在使用Vista并遇到麻烦).
- 重新启动Apache.
现在,您可以通过浏览到 http://transitcalculator.localhost/来访问该目录.
创建别名
-
从您的
http.conf
文件的第200行开始,在<目录"C:/xampp/htdocs">
和</Directory>
(〜第232行),然后将其粘贴到下面,并以C:/xampp/htdocs
替换为所需的目录(在本例中为C:/Projects
)为您的服务器授予新目录的正确权限. -
找到
< IfModule alias_module></IfModule>
部分(〜第300行)并添加别名/transitCalculator"C:/Projects/transitCalculator/trunk"
中
Alias
注释块下方的(或与您的需求相关的任何东西).
更改文档根目录
-
在C:\ xampp \ apache \ conf \ httpd.conf中编辑〜176行;将
DocumentRoot"C:/xampp/htdocs"
更改为#DocumentRoot"C:/Projects"
(或您想要的任何内容). -
编辑〜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
- Open C:\xampp\apache\conf\extra\httpd-vhosts.conf.
- Un-comment ~line 19 (
NameVirtualHost *:80
). 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>
Open your hosts file (C:\Windows\System32\drivers\etc\hosts).
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).
- 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).
- Restart Apache.
Now you can access that directory by browsing to http://transitcalculator.localhost/.
Make an Alias
Starting ~line 200 of your
http.conf
file, copy everything between<Directory "C:/xampp/htdocs">
and</Directory>
(~line 232) and paste it immediately below withC:/xampp/htdocs
replaced with your desired directory (in this caseC:/Projects
) to give your server the correct permissions for the new directory.Find the
<IfModule alias_module></IfModule>
section (~line 300) and addAlias /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
Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change
DocumentRoot "C:/xampp/htdocs"
to#DocumentRoot "C:/Projects"
(or whatever you want).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屋!