php 如何为不同的根目录配置 xampp Web 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18902887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to configuring a xampp web server for different root directory
提问by vardius
The web directory is the home of all of your application's public and static files. Including images, stylesheets and JavaScript files. It is also where the front controllers live.
web 目录是所有应用程序的公共和静态文件的主目录。包括图像、样式表和 JavaScript 文件。这也是前端控制器所在的地方。
So the question is when i install and set up xampp my web directory is:
所以问题是当我安装和设置 xampp 时,我的 web 目录是:
xampp\htdocs
and I want to set it up for:
我想设置它:
xampp\htdocs\myproject\web
How to do it?
Now when I type in my browser the address: http://localhost/
I enter xampp\htdocs
directory
and I want to type in my browser the address: http://localhost/
and enter xampp\htdocs\myproject\web
directory
怎么做?现在,当我在浏览器中输入地址时:http://localhost/
我输入xampp\htdocs
目录
,我想在浏览器中http://localhost/
输入地址:然后输入xampp\htdocs\myproject\web
目录
回答by blckwngd
You can change Apaches httpd.conf by clicking (in xampp control panel) apache/conf/httpd.conf
and adjust the entries for DocumentRoot
and the corresponding Directory
entry.
Just Ctrl+Ffor "htdocs" and change the entries to your new path.
您可以通过单击(在 xampp 控制面板中)更改 Apaches httpd.confapache/conf/httpd.conf
并调整DocumentRoot
相应Directory
条目的条目。只需Ctrl+F为“htdocs”并将条目更改为您的新路径。
回答by LALIT JAMNAL
- Go to C:\xampp\apache\conf\httpd.conf
- Open httpd.conf
- Find tag : DocumentRoot "C:/xampp/htdocs"
- Edit tag to : DocumentRoot "C:/xampp/htdocs/myproject/web"
Now find tag and change it to < Directory "C:/xampp/htdocs/myproject/web" >
Restart Your Apache
- 转到 C:\xampp\apache\conf\httpd.conf
- 打开 httpd.conf
- 查找标签:DocumentRoot "C:/xampp/htdocs"
- 将标签编辑为:DocumentRoot "C:/xampp/htdocs/myproject/web"
现在找到标签并将其更改为<目录“C:/xampp/htdocs/myproject/web”>
重启你的 Apache
回答by user1585863
In case, if anyone prefers a simpler solution, especially on Linux (e.g. Ubuntu), a very easy way out is to create a symbolic link to the intended folder in the htdocs folder. For example, if I want to be able to serve files from a folder called "/home/some/projects/testserver/" and my htdocs is located in "/opt/lampp/htdocs/". Just create a symbolic link like so:
如果有人更喜欢更简单的解决方案,尤其是在 Linux(例如 Ubuntu)上,一个非常简单的方法是在 htdocs 文件夹中创建一个指向目标文件夹的符号链接。例如,如果我希望能够从名为“/home/some/projects/testserver/”的文件夹中提供文件,并且我的 htdocs 位于“/opt/lampp/htdocs/”中。只需像这样创建一个符号链接:
ln -s /home/some/projects/testserver /opt/lampp/htdocs/testserver
The command for symbolic link works like so:
ln -s target source
where,
符号链接命令的工作方式如下:
ln -s target source
where,
target - The existing file/directory you would like to link TO.
source - The file/folder to be created, copying the contents of the target. The LINK itself.
For more help see ln --help Source: Create Symbolic Links in Ubuntu
如需更多帮助,请参阅 ln --help 来源:在 Ubuntu 中创建符号链接
And that's done. just visit http://localhost/testserver/In fact, you don't even need to restart your server.
这已经完成了。只需访问http://localhost/testserver/实际上,您甚至不需要重新启动服务器。
回答by insCode
ok guys you are not going to believe me how easy it is, so i putted a video on YouTube to show you that [ click here]
好吧,伙计们,你们不会相信我有多容易,所以我在 YouTube 上放了一个视频来向你们展示 [点击这里]
now , steps :
现在,步骤:
- run your xampp control panel
- click the button saying config
- select apache( httpd.conf )
- find document root
- replace
- 运行您的 xampp 控制面板
- 点击按钮说配置
- 选择 apache( httpd.conf )
- 找到文档根
- 代替
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
those 2 lines || C:/xampp/htdocs == current location for root || change C:/xampp/htdocs with any location you want
那两行 || C:/xampp/htdocs == root 的当前位置 || 将 C:/xampp/htdocs 更改为您想要的任何位置
- save it DONE: start apache and go to the localhost see in action [ watch video click here]
- 保存完成:启动 apache 并转到本地主机查看操作 [观看视频单击此处]
回答by akvermaktr
I moved my htdocs folder from C:\xampp\htdocs to D:\htdocs without editing the Apache config file (httpd.conf).
我将我的 htdocs 文件夹从 C:\xampp\htdocs 移动到 D:\htdocs 而不编辑 Apache 配置文件 (httpd.conf)。
Step 1) Move C:\xampp\htdocs
folder to D:\htdocs
Step 2) Create a symbolic link in C:\xampp\htdocs linked to D:\htdocs using mklink command.
步骤 1) 将C:\xampp\htdocs
文件夹移动到D:\htdocs
步骤 2) 使用 mklink 命令在 C:\xampp\htdocs 中创建链接到 D:\htdocs 的符号链接。
D:\>mklink /J C:\xampp\htdocs D:\htdocs
Junction created for C:\xampp\htdocs <<===>> D:\htdocs
D:\>
Step 3) Done!
第 3 步)完成!
回答by Homesh Paul
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
Write above code inside following tags < Directory "c:\projects" > < / Directory > c:(you can add any directory d: e:) is drive where you have created your project folder.
将上面的代码写在以下标签中 < Directory "c:\projects" > </ Directory > c:(您可以添加任何目录 d: e:) 是您创建项目文件夹的驱动器。
Alias /projects "c:\projects"
别名 /projects "c:\projects"
Now you can access the pr0jects directory on your browser :
现在您可以在浏览器上访问 pr0jects 目录:
localhost/projects/
本地主机/项目/
回答by Roman Pelikh
If you are running xampp on linuxbased image, to change root directory open:
如果您在基于linux的映像上运行xampp,要更改打开的根目录:
/opt/lampp/etc/httpd.conf
Change default document root:
DocumentRoot "/opt/lampp/htdocs" and <Directory "/opt/lampp/htdocs"
更改默认文档根目录:
DocumentRoot "/opt/lampp/htdocs" and <Directory "/opt/lampp/htdocs"
to your folder DocumentRoot "/opt/lampp/htdocs/myFolder" and <Directory "/opt/lampp/htdocs/myFolder">
到你的文件夹 DocumentRoot "/opt/lampp/htdocs/myFolder" and <Directory "/opt/lampp/htdocs/myFolder">
回答by kaya
You can also put in a new virtual Host entry in the
您还可以在
c:\xampp\apache\conf\httpd-vhosts.conf
c:\xampp\apache\conf\httpd-vhosts.conf
like:
喜欢:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/xampp/htdocs/myproject/web"
ServerName localhost
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
回答by Koushal Pateriya
You can change the port while you open your XAMP control panel, follow the steps:
您可以在打开 XAMP 控制面板时更改端口,请按照以下步骤操作:
- click on config net to the start button, and
- select
httpd.conf
, a text file will open - check the file and file
listen:80
, - once got
listen:80
replace withlisten:8080
and - save in the the same folder.
- 单击 config net 到开始按钮,然后
- 选择
httpd.conf
,将打开一个文本文件 - 检查文件和文件
listen:80
, - 一旦被
listen:80
替换为listen:8080
和 - 保存在同一个文件夹中。
Once done that, you will be able to start your local server.
完成后,您将能够启动本地服务器。