简体   繁体   English

在Htdoc Webroot之间切换-更改“ httpd.conf”中的“ DocumentRoot”变量还是使用符号链接?

[英]Switching between Htdoc Webroots - Change my “DocumentRoot” variable in “httpd.conf” or use Symbolic Links?

I've officially reached the end of my wits on this problem. 我已经正式解决了这个问题。 As someone who constantly works on several websites at a time (I'm sure I'm not alone here), it becomes frustrating renaming my "htdocs" directory whenever I want to work on a different site, so I decided to throw together a simple script. 作为一个经常一次在多个网站上工作的人(我敢肯定我在这里并不孤单),每当我想在其他网站上工作时,重命名我的“ htdocs”目录都会变得令人沮丧,因此我决定将一个简单的脚本。

My first approach was to reset the "DocumentRoot" variable in "httpd.conf" based on the directory input I provided, however, having a DocumentRoot outside of the main "/Applications/XAMPP/" directory has proven to be a bigger problem. 我的第一种方法是根据我提供的目录输入来重置“ httpd.conf”中的“ DocumentRoot”变量,但是事实证明,将DocumentRoot放在主目录“ / Applications / XAMPP /”之外是一个更大的问题。 As you can see, I'm running OSX with an XAMPP installation. 如您所见,我正在通过XAMPP安装运行OSX。 Ideally, I'd like to have all my sites located at "/Users/Me/Sites/*". 理想情况下,我希望所有站点都位于“ / Users / Me / Sites / *”。 Even when I tried to move my sites within XAMPP's base directory, Apache does not want to load anything other than "htdocs" as my DocumentRoot. 即使当我试图在XAMPP的基本目录中移动站点时,Apache也不想将除“ htdocs”以外的任何内容加载为DocumentRoot。

My next approach was to simply add symbolic links to all the files/directories within each site I was working on at the time to "htdocs". 我的下一种方法是简单地将指向我当时正在工作的每个站点内所有文件/目录的符号链接添加到“ htdocs”。 This loads fine in the browser for basic html files, however, I work primarily with PHP and this does not appear to want to render (I can see the file but it will not display as a webpage). 对于基本的html文件,这在浏览器中可以很好地加载,但是,我主要使用PHP,并且似乎不需要渲染(我可以看到该文件,但它不会显示为网页)。

Neither of these approaches in themselves sound too difficult, but from learning Xcode, to AppleScript, to Apache's httpd.conf documentation, I feel I've experienced enough headaches. 这些方法本身听起来都不是太困难,但是从学习Xcode到AppleScript,再到Apache的httpd.conf文档,我都感到头疼。 I've played with permissions for each attempt I've gone through and nothing has panned out for me yet. 我尝试过的每一次尝试均具有权限,但还没有发现任何进展。

I'm sure there are plenty of other webdesigners out there who have faced this problem in the past, what's your solution? 我敢肯定,过去还有很多其他的Web设计人员都遇到过这个问题,您有什么解决方案?

This is actually really easily achieved, given that you are using XAMPP, I am not 100% but if you go under /bin/apache2/conf/extras/ you should see a file called httpd-vhosts.conf in this file you can add as many virtual hosts as you want. 鉴于您使用的是XAMPP,实际上这确实很容易实现,但我不是100%,但是如果进入/bin/apache2/conf/extras/ ,则应该在此文件中看到一个名为httpd-vhosts.conf的文件,您可以添加所需数量的虚拟主机。 Make sure you set the ServerName to be something unique. 确保将ServerName设置为唯一。 Once that is done, make sure that the Include Vhosts is enabled in the httpd.conf 完成此操作后,请确保已在httpd.conf启用“包括虚拟主机”

Now, you just edit your hosts file. 现在,您只需编辑主机文件。 I am not sure where this is on OSX, since it is linux based I would say /etc/hosts but google will help you. 我不确定这在OSX上的位置,因为它是基于Linux的,所以我会说/etc/hosts但是Google会帮助您。 Add a line for each of your sites like so: 为您的每个站点添加一行,如下所示:

127.0.0.1     site1.dev
127.0.0.1     site2.dev

etc. Now restart apache and in your browser type site1.dev and apache should understand it and take you to that site. 等等。现在重新启动apache,并在浏览器中键入site1.dev ,apache应该理解它并带您到该站点。 Pretty simple. 很简单

Brad's solution should work. 布拉德的解决方案应该起作用。

If you are on OSX, you might also want to check out MAMP (http://www.mamp.info/en/index.html). 如果您使用的是OSX,则可能还需要检出MAMP(http://www.mamp.info/en/index.html)。 There is a free and "Pro" version. 有一个免费的“ Pro”版本。 I've only used the free version but it's pretty drop dead simple to change the root directory from one project to the other. 我只使用了免费版本,但是将根目录从一个项目更改为另一个项目非常简单。 Only kind of gotcha is the MySQL which uses a socket to connect but if you know what you are doing, this isn't a big deal. MySQL只是一种陷阱,它使用套接字进行连接,但是如果您知道自己在做什么,那没什么大不了的。

Once you'll understand the virtualHost things, let'say you'll use names based virtualhosts and edit you host file to get all theses names matching your development server IP, once done, you'll see you will have to adjust documentRoot and directory settings on all theses virtualhosts for each new project. 了解了VirtualHost的内容之后,假设您将使用基于名称的虚拟主机并编辑主机文件,以使所有这些名称与开发服务器IP匹配,完成后,您将看到必须调整documentRoot和目录每个新项目的所有这些虚拟主机上的设置。

So a generic solution exists: mod_vhost_alias : http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html All you virtualhosts will be the same, with variables (documentRoot, serverName,etc). 因此,存在一个通用的解决方案:mod_vhost_alias: http ://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html所有虚拟主机都将是相同的,但具有变量(documentRoot,serverName等)。 If you want specific setting for some projects ensure you have allowed .htaccess files and set the specific things there. 如果要为某些项目进行特定设置,请确保已允许.htaccess文件并在那里进行特定设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM