在 htdocs 文件夹之外制作 XAMPP/Apache 服务文件 [英] Make XAMPP / Apache serve file outside of htdocs folder
问题描述
是否可以配置 xampp 以提供 htdocs
目录?
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
和我的 xampp 文件通常来自:
and my xampp files are normally served out from:
C:\xampp\htdocs\
(因为这是默认配置)有什么方法可以让 Apache 识别并提供我的 TransitCalculator.php
文件而不将它移到 htdocs
下?最好我希望 Apache 提供/访问项目目录的全部内容,并且我不想将项目目录移动到 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
.
编辑以将 Apache 添加到问题标题中,使问答更可搜索"
edit: edited to add Apache to the question title to make Q/A more "searchable"
推荐答案
好的,根据 pix0r,Sparks' 和 Dave 的回答看起来有三种方法可以做到这一点:
Ok, per pix0r's, Sparks' and Dave's answers it looks like there are three ways to do this:
- 打开 C:\xampp\apache\conf\extra\httpd-vhosts.conf.
- 取消注释 ~line 19 (
NameVirtualHost *:80
). 添加您的虚拟主机(~第 36 行):
- 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>
打开您的主机文件 (C:\Windows\System32\drivers\etc\hosts).
Open your hosts file (C:\Windows\System32\drivers\etc\hosts).
添加
127.0.0.1 transitcalculator.localhost #transitCalculator
到文件末尾(在 Spybot 之前 - 如果您安装了搜索和销毁内容).
to the end of the file (before the Spybot - Search & Destroy stuff if you have that installed).
现在您可以通过浏览到 http://transitcalculator.localhost/ 来访问该目录.
Now you can access that directory by browsing to http://transitcalculator.localhost/.
从
http.conf
文件的第 200 行开始,复制
和之间的所有内容></Directory>
(~第 232 行)并将其粘贴在下面,C:/xampp/htdocs
替换为您想要的目录(在本例中为C:/Projects
) 为您的服务器提供新目录的正确权限.
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.
找到
部分(~第 300 行)并添加
Find the <IfModule alias_module></IfModule>
section (~line 300) and add
Alias /transitCalculator "C:/Projects/transitCalculator/trunk"
(或任何与您的需求相关的内容)在 Alias
注释块下方,在模块标签内.
(or whatever is relevant to your desires) below the Alias
comment block, inside the module tags.
<小时>
更改您的文档根目录
在 C:\xampp\apache\conf\httpd.conf 中编辑 ~line 176;将
DocumentRoot "C:/xampp/htdocs"
更改为#DocumentRoot "C:/Projects"
(或任何你想要的).
Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change
DocumentRoot "C:/xampp/htdocs"
to#DocumentRoot "C:/Projects"
(or whatever you want).
编辑 ~line 203 以匹配您的新位置(在本例中为 C:/Projects
).
Edit ~line 203 to match your new location (in this case C:/Projects
).
<小时>
注意事项:
- 您必须使用正斜杠/"而不是反斜杠\".
- 不要在末尾包含尾随的/".
- 重启你的服务器.
这篇关于在 htdocs 文件夹之外制作 XAMPP/Apache 服务文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!