在 Htdoc Webroot 之间切换 - 更改我的“DocumentRoot” “httpd.conf”中的变量或者使用符号链接?
我已经正式对这个问题束手无策了。作为一个经常同时在多个网站上工作的人(我确信我并不孤单),每当我想在不同的网站上工作时,重命名我的“htdocs”目录就会变得令人沮丧,所以我决定将一个简单的脚本。
我的第一种方法是根据我提供的目录输入重置“httpd.conf”中的“DocumentRoot”变量,但是,事实证明,在主“/Applications/XAMPP/”目录之外有一个 DocumentRoot 是一个更大的问题。如您所见,我正在运行带有 XAMPP 安装的 OSX。理想情况下,我希望我的所有网站都位于“/Users/Me/Sites/*”。即使当我尝试将我的站点移动到 XAMPP 的基本目录中时,Apache 也不想加载除“htdocs”之外的任何内容作为我的 DocumentRoot。
我的下一个方法是简单地将符号链接添加到我当时正在处理的每个站点内的所有文件/目录到“htdocs”。对于基本的 html 文件,这在浏览器中加载得很好,但是,我主要使用 PHP,这似乎不想渲染(我可以看到该文件,但它不会显示为网页)。
这两种方法本身听起来都不太困难,但从学习 Xcode,到 AppleScript,再到 Apache 的 httpd.conf 文档,我觉得我已经经历够头痛了。我已经为我所经历的每一次尝试都赋予了权限,但还没有任何结果。
我确信有很多其他网页设计师过去也遇到过这个问题,您的解决方案是什么?
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.
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. As you can see, I'm running OSX with an XAMPP installation. Ideally, I'd like to have all my sites located at "/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.
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". 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).
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. 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上很容易实现,考虑到您使用的是 XAMPP,我不是 100%,但是如果您进入
/bin/apache2/conf/extras/
您应该看到一个名为httpd 的文件-vhosts.conf 在此文件中,您可以添加任意数量的虚拟主机。确保将
ServerName
设置为唯一的。完成后,请确保在httpd.conf
中启用“包含虚拟主机”。现在,您只需编辑主机文件即可。我不确定它在 OSX 上的位置,因为它是基于 Linux 的,我会说
/etc/hosts
但 google 会帮助你。为每个站点添加一行,如下所示:等等。现在重新启动 apache 并在浏览器中输入
site1.dev
,apache 应该会理解它并带您访问该站点。很简单。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 calledhttpd-vhosts.conf
in this file you can add as many virtual hosts as you want. Make sure you set theServerName
to be something unique. Once that is done, make sure that the Include Vhosts is enabled in thehttpd.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. Add a line for each of your sites like so:etc. Now restart apache and in your browser type
site1.dev
and apache should understand it and take you to that site. Pretty simple.布拉德的解决方案应该有效。
如果您使用的是 OSX,您可能还想查看 MAMP (http://www.mamp.info/en/index.html)。有免费版和“专业版”。我只使用了免费版本,但将根目录从一个项目更改为另一个项目非常简单。唯一的问题是 MySQL 使用套接字进行连接,但如果您知道自己在做什么,那么这并不是什么大问题。
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). There is a free and "Pro" version. 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.
一旦您了解了 virtualHost 的内容,假设您将使用基于名称的虚拟主机并编辑主机文件以获得与您的开发服务器 IP 匹配的所有这些名称,完成后,您将看到必须调整 documentRoot 和目录每个新项目的所有这些虚拟主机上的设置。
因此存在通用解决方案: mod_vhost_alias : http://httpd.apache.org/docs /2.2/mod/mod_vhost_alias.html
所有虚拟主机都是相同的,带有变量(documentRoot、serverName 等)。如果您想要对某些项目进行特定设置,请确保您已允许 .htaccess 文件并在那里设置特定内容。
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.
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). If you want specific setting for some projects ensure you have allowed .htaccess files and set the specific things there.