Is it possible to configure xampp to serve up a file outside of the htdocs
directory?
是否可以配置xampp来提供htdocs目录之外的文件?
For instance, say I have a file located as follows:
例如,假设我有如下文件:
C:\projects\transitCalculator\trunk\TransitCalculator.php
C:\ \ transitCalculator \树干\ TransitCalculator.php项目
and my xampp files are normally served out from:
我的xampp文件通常来自:
C:\xampp\htdocs\
C:\ xampp \根\
(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识别并提供我的TransitCalculator。php文件没有移动它在htdocs下?我希望Apache能够提供/访问项目目录的全部内容,并且我不希望将项目目录移动到htdocs下。
edit: edited to add Apache to the question title to make Q/A more "searchable"
编辑:将Apache添加到问题标题中,使Q/A更“可搜索”
6 个解决方案
#1
325
Ok, per pix0r's, Sparks' and Dave's answers it looks like there are three ways to do this:
根据pix0r, Sparks和Dave的回答看起来有三种方法可以做到:
Virtual Hosts
- Open C:\xampp\apache\conf\extra\httpd-vhosts.conf.
- 打开C:\ xampp \ apache \ conf \额外\ httpd-vhosts.conf。
- Un-comment line 19 (
NameVirtualHost *:80
). - Un-comment line 19 (NameVirtualHost *:80)。
-
Add your virtual host (~line 36):
添加虚拟主机(~第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).
打开你的主机文件(C:\Windows\System32\驱动器\等等)。
-
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).
- 保存(您可能需要将它保存到桌面,更改旧主机文件的权限(右键单击>属性),如果您使用Vista并且遇到问题,则将新文件复制到旧文件的目录中(或者重命名旧文件)。
- Restart Apache.
- 重新启动Apache。
Now you can access that directory by browsing to http://transitcalculator.localhost/.
现在可以通过浏览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.开始~ http的第200行。conf文件,复制
和 (~第232行)之间的所有内容,并将其直接粘贴到下面,用您想要的目录(在本例中为C:/Projects)替换为C:/xampp/htdocs,为您的服务器提供新目录的正确权限。 -
Find the
<IfModule alias_module></IfModule>
section (~line 300) and add找到
section(~第300行)并添加 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
-
Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change
DocumentRoot "C:/xampp/htdocs"
to#DocumentRoot "C:/Projects"
(or whatever you want).编辑~第176行C:\xampp\apache\conf\httpd.conf;将DocumentRoot“C:/xampp/htdocs”改为#DocumentRoot“C:/Projects”(或任何你想要的)。
-
Edit ~line 203 to match your new location (in this case
C:/Projects
).编辑~第203行以匹配您的新位置(在本例中为C:/Projects)。
Notes:
注:
- You have to use forward slashes "/" instead of back slashes "\".
- 你必须使用前斜杠"/"而不是后斜杠"\"。
- Don't include the trailing "/" at the end.
- 不要在结尾加上结尾的"/"。
- restart your server.
- 重新启动服务器。
#2
90
You can relocate it by editing the DocumentRoot setting in XAMPP\apache\conf\httpd.conf.
您可以通过编辑XAMPP\apache\conf\httpd.conf中的DocumentRoot设置来重新定位它。
It should currently be:
目前应该是:
C:/xampp/htdocs
C:/ xampp /根
Change it to:
把它改成:
C:/projects/transitCalculator/trunk
C:/项目/ transitCalculator /树干
#3
49
A VirtualHost would also work for this and may work better for you as you can host several projects without the need for subdirectories. Here's how you do it:
虚拟主机也适用于此,并且可能更适合您,因为您可以在不需要子目录的情况下托管多个项目。你可以这样做:
httpd.conf (or extra\httpd-vhosts.conf relative to httpd.conf. Trailing slashes "\" might cause it not to work):
httpd。conf(或额外\ httpd-vhosts。conf相对于httpd . conf。拖后的斜杠“\”可能导致它不工作):
NameVirtualHost *:80
# ...
<VirtualHost *:80>
DocumentRoot C:\projects\transitCalculator\trunk\
ServerName transitcalculator.localhost
<Directory C:\projects\transitCalculator\trunk\>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
HOSTS file (c:\windows\system32\drivers\etc\hosts usually):
主机文件(c:\ windows \ system32系统\司机等\ \主机通常):
# localhost entries
127.0.0.1 localhost transitcalculator.localhost
Now restart XAMPP and you should be able to access http://transitcalculator.localhost/ and it will map straight to that directory.
现在重新启动XAMPP,您应该能够访问http://transitcalculator。localhost/它将直接映射到那个目录。
This can be helpful if you're trying to replicate a production environment where you're developing a site that will sit on the root of a domain name. You can, for example, point to files with absolute paths that will carry over to the server:
如果您正在尝试复制一个生产环境,您正在开发一个位于域名根的站点,那么这将非常有用。例如,您可以指向带有将传送到服务器的绝对路径的文件:
<img src="/images/logo.png" alt="My Logo" />
whereas in an environment using aliases or subdirectories, you'd need keep track of exactly where the "images" directory was relative to the current file.
而在使用别名或子目录的环境中,您需要跟踪“图像”目录相对于当前文件的确切位置。
#4
15
You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form.
您可以将Apache设置为在任何有限制的地方服务页面,但是它通常以更安全的形式分发。
Editing your apache files (http.conf is one of the more common names) will allow you to set any folder so it appears in your webroot.
编辑apache文件(http)。conf是更常见的名称之一)将允许您设置任何文件夹,以便它出现在您的webroot中。
EDIT:
编辑:
alias myapp c:\myapp\
别名myapp c:\ myapp \
I've edited my answer to include the format for creating an alias in the http.conf file which is sort of like a shortcut in windows or a symlink under un*x where Apache 'pretends' a folder is in the webroot. This is probably going to be more useful to you in the long term.
我编辑了我的答案,以包含在http中创建别名的格式。conf文件有点像windows中的快捷方式或者un*x下的symlink, Apache在webroot中“假装”一个文件夹。从长远来看,这可能对你更有用。
#5
8
As a side note, if you're trying to get XAMPP to use a network drive as your document root you have to use UNC paths in httpd.conf. XAMPP will not recognize your mapped network drives.
顺便说一句,如果您想让XAMPP使用网络驱动器作为文档根,那么必须在httpd.conf中使用UNC路径。XAMPP将无法识别映射的网络驱动器。
For example the following won't work, DocumentRoot "X:/webroot"
例如,下面的方法行不通,DocumentRoot用户"X:/webroot"
But this will, DocumentRoot "//192.168.10.100/webroot" (note the forward slashes, not back slashes)
但这将是,DocumentRoot "/ 192.168.10.100/webroot"(注意前斜杠,而不是后斜杠)
#6
4
None of these solutions worked easily. Here is the simplest solution to allow Apache 2 to host websites outside of htdocs:
这些解决方案都不容易。下面是允许Apache 2在htdocs之外托管网站的最简单的解决方案:
Underneath the "DocumentRoot" directive in httpd.conf, you should see a directory block. Replace this directory block with:
在httpd中的“DocumentRoot”指令下面。conf,您应该看到一个目录块。将此目录块替换为:
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
REMEMBER NOT TO USE THIS CONFIGURATION IN A REAL ENVIRONMENT
记住不要在真实的环境中使用这个配置
#1
325
Ok, per pix0r's, Sparks' and Dave's answers it looks like there are three ways to do this:
根据pix0r, Sparks和Dave的回答看起来有三种方法可以做到:
Virtual Hosts
- Open C:\xampp\apache\conf\extra\httpd-vhosts.conf.
- 打开C:\ xampp \ apache \ conf \额外\ httpd-vhosts.conf。
- Un-comment line 19 (
NameVirtualHost *:80
). - Un-comment line 19 (NameVirtualHost *:80)。
-
Add your virtual host (~line 36):
添加虚拟主机(~第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).
打开你的主机文件(C:\Windows\System32\驱动器\等等)。
-
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).
- 保存(您可能需要将它保存到桌面,更改旧主机文件的权限(右键单击>属性),如果您使用Vista并且遇到问题,则将新文件复制到旧文件的目录中(或者重命名旧文件)。
- Restart Apache.
- 重新启动Apache。
Now you can access that directory by browsing to http://transitcalculator.localhost/.
现在可以通过浏览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.开始~ http的第200行。conf文件,复制
和 (~第232行)之间的所有内容,并将其直接粘贴到下面,用您想要的目录(在本例中为C:/Projects)替换为C:/xampp/htdocs,为您的服务器提供新目录的正确权限。 -
Find the
<IfModule alias_module></IfModule>
section (~line 300) and add找到
section(~第300行)并添加 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
-
Edit ~line 176 in C:\xampp\apache\conf\httpd.conf; change
DocumentRoot "C:/xampp/htdocs"
to#DocumentRoot "C:/Projects"
(or whatever you want).编辑~第176行C:\xampp\apache\conf\httpd.conf;将DocumentRoot“C:/xampp/htdocs”改为#DocumentRoot“C:/Projects”(或任何你想要的)。
-
Edit ~line 203 to match your new location (in this case
C:/Projects
).编辑~第203行以匹配您的新位置(在本例中为C:/Projects)。
Notes:
注:
- You have to use forward slashes "/" instead of back slashes "\".
- 你必须使用前斜杠"/"而不是后斜杠"\"。
- Don't include the trailing "/" at the end.
- 不要在结尾加上结尾的"/"。
- restart your server.
- 重新启动服务器。
#2
90
You can relocate it by editing the DocumentRoot setting in XAMPP\apache\conf\httpd.conf.
您可以通过编辑XAMPP\apache\conf\httpd.conf中的DocumentRoot设置来重新定位它。
It should currently be:
目前应该是:
C:/xampp/htdocs
C:/ xampp /根
Change it to:
把它改成:
C:/projects/transitCalculator/trunk
C:/项目/ transitCalculator /树干
#3
49
A VirtualHost would also work for this and may work better for you as you can host several projects without the need for subdirectories. Here's how you do it:
虚拟主机也适用于此,并且可能更适合您,因为您可以在不需要子目录的情况下托管多个项目。你可以这样做:
httpd.conf (or extra\httpd-vhosts.conf relative to httpd.conf. Trailing slashes "\" might cause it not to work):
httpd。conf(或额外\ httpd-vhosts。conf相对于httpd . conf。拖后的斜杠“\”可能导致它不工作):
NameVirtualHost *:80
# ...
<VirtualHost *:80>
DocumentRoot C:\projects\transitCalculator\trunk\
ServerName transitcalculator.localhost
<Directory C:\projects\transitCalculator\trunk\>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
HOSTS file (c:\windows\system32\drivers\etc\hosts usually):
主机文件(c:\ windows \ system32系统\司机等\ \主机通常):
# localhost entries
127.0.0.1 localhost transitcalculator.localhost
Now restart XAMPP and you should be able to access http://transitcalculator.localhost/ and it will map straight to that directory.
现在重新启动XAMPP,您应该能够访问http://transitcalculator。localhost/它将直接映射到那个目录。
This can be helpful if you're trying to replicate a production environment where you're developing a site that will sit on the root of a domain name. You can, for example, point to files with absolute paths that will carry over to the server:
如果您正在尝试复制一个生产环境,您正在开发一个位于域名根的站点,那么这将非常有用。例如,您可以指向带有将传送到服务器的绝对路径的文件:
<img src="/images/logo.png" alt="My Logo" />
whereas in an environment using aliases or subdirectories, you'd need keep track of exactly where the "images" directory was relative to the current file.
而在使用别名或子目录的环境中,您需要跟踪“图像”目录相对于当前文件的确切位置。
#4
15
You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form.
您可以将Apache设置为在任何有限制的地方服务页面,但是它通常以更安全的形式分发。
Editing your apache files (http.conf is one of the more common names) will allow you to set any folder so it appears in your webroot.
编辑apache文件(http)。conf是更常见的名称之一)将允许您设置任何文件夹,以便它出现在您的webroot中。
EDIT:
编辑:
alias myapp c:\myapp\
别名myapp c:\ myapp \
I've edited my answer to include the format for creating an alias in the http.conf file which is sort of like a shortcut in windows or a symlink under un*x where Apache 'pretends' a folder is in the webroot. This is probably going to be more useful to you in the long term.
我编辑了我的答案,以包含在http中创建别名的格式。conf文件有点像windows中的快捷方式或者un*x下的symlink, Apache在webroot中“假装”一个文件夹。从长远来看,这可能对你更有用。
#5
8
As a side note, if you're trying to get XAMPP to use a network drive as your document root you have to use UNC paths in httpd.conf. XAMPP will not recognize your mapped network drives.
顺便说一句,如果您想让XAMPP使用网络驱动器作为文档根,那么必须在httpd.conf中使用UNC路径。XAMPP将无法识别映射的网络驱动器。
For example the following won't work, DocumentRoot "X:/webroot"
例如,下面的方法行不通,DocumentRoot用户"X:/webroot"
But this will, DocumentRoot "//192.168.10.100/webroot" (note the forward slashes, not back slashes)
但这将是,DocumentRoot "/ 192.168.10.100/webroot"(注意前斜杠,而不是后斜杠)
#6
4
None of these solutions worked easily. Here is the simplest solution to allow Apache 2 to host websites outside of htdocs:
这些解决方案都不容易。下面是允许Apache 2在htdocs之外托管网站的最简单的解决方案:
Underneath the "DocumentRoot" directive in httpd.conf, you should see a directory block. Replace this directory block with:
在httpd中的“DocumentRoot”指令下面。conf,您应该看到一个目录块。将此目录块替换为:
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
REMEMBER NOT TO USE THIS CONFIGURATION IN A REAL ENVIRONMENT
记住不要在真实的环境中使用这个配置