简体   繁体   English

如何在 Mac OS X 上使用 /home 目录

[英]How can I use the /home directory on Mac OS X

I've got a Mac that I can run either the Leopard (10.5) or Snow Leopard (10.6) version of OS X on.我有一台 Mac,可以运行 Leopard (10.5) 或 Snow Leopard (10.6) 版本的 OS X。 I'm using it to do web development/testing before publishing files to my production host.在将文件发布到我的生产主机之前,我用它来进行 Web 开发/测试。

On the production host my site's doc root is under the home directory (eg /home/stimulatingpixels/public_html) and I'd like to duplicate that location on the Mac.在生产主机上,我网站的文档根目录位于主目录下(例如 /home/stimulatingpixels/public_html),我想在 Mac 上复制该位置。 Unfortunately, their is a hidden and lock placeholder on the Mac that looks like a mounted drive with nothing in it sitting in the /home location.不幸的是,它们是 Mac 上的一个隐藏和锁定占位符,看起来像一个已安装的驱动器,其中没有任何内容位于 /home 位置。

I know from experience that it's unwise to move this and drop in your own /home directory because upgrades can cause it to be erased (and it doesn't get stored in the TimeMachine backup, by the way).我从经验中知道,将其移动并放入您自己的 /home 目录是不明智的,因为升级会导致它被删除(顺便说一句,它不会存储在 TimeMachine 备份中)。

So, the question, is there anyway to safely use /home on a Mac either Leopard or Snow Leopard?所以,问题是,无论如何都可以在 Mac 上安全地使用 /home,无论是 Leopard 还是 Snow Leopard?

(Note: I realize this is very Mac specific and will be asking it in an Apple forum as well. Just wanted to ask here in addition to cover all the bases.) (注意:我意识到这是 Mac 特有的,也会在 Apple 论坛上提问。除了涵盖所有基础之外,我只想在这里提问。)

Update: To help describe why I want to do this, in addition to the front end web site, I've got a series of scripts that I'd like to run as well.更新:为了帮助描述我为什么要这样做,除了前端网站之外,我还有一系列我想运行的脚本。 One of the main goals with being able to use the /home directory (and more specifically the same path from the servers root) is so that can use the same output paths on the development mac as well be used on the production server.能够使用 /home 目录(更具体地说是来自服务器根目录的相同路径)的主要目标之一是可以在开发 mac 上使用相同的输出路径,也可以在生产服务器上使用。 I know there are ways to work around this, but I'd rather not have to deal with it.我知道有办法解决这个问题,但我宁愿不必处理它。 The real goal is to have all the files on the development Mac have the same filepath from the / root of the directory tree as the production server.真正的目标是让开发 Mac 上的所有文件与生产服务器的目录树的 / 根具有相同的文件路径。

Another Update: The other reason that I forgot to mention earlier for this is setting up .htaccess paths when using basic authentication.另一个更新:我之前忘记提及的另一个原因是在使用基本身份验证时设置 .htaccess 路径。 Since those paths are from the file system root instead of the website docroot, they end up going through "/home" when that's part of the tree.由于这些路径来自文件系统根目录而不是网站文档根目录,因此当它是树的一部分时,它们最终会通过“/home”。

NOTE: As of 2015, I no longer use or recommend this method.注意:自 2015 年起,我不再使用或推荐这种方法。 Instead I use Vagrant to setup virtual machines for dev and testing.相反,我使用Vagrant来设置用于开发和测试的虚拟机。 It's free, relatively easy, and allows better matching of the production environment.它是免费的,相对容易,并且可以更好地匹配生产环境。 It completely separates the development environment and you can make as many as you need.它完全分离了开发环境,您可以根据需要制作任意数量。 Highly recommended .强烈推荐 I'm leaving the original answer below for posterity's sake.为了后代的缘故,我将在下面留下原始答案。


I found an answer here on the Apple forums .在 Apple 论坛上找到了答案。

In order to reclaim the /home directory, edit the /etc/auto_master file and comment out (or remove) the line with /home in it.为了回收/home目录,编辑/etc/auto_master文件并注释掉(或删除)其中包含/home的行。 You'll need to reboot after this for the change to take effect (or, per nilbus' comment, try running sudo automount -vc ).在此之后您需要重新启动以使更改生效(或者,根据 nilbus 的评论,尝试运行sudo automount -vc )。 This works with Mac OS X 10.5 (Leopard).这适用于 Mac OS X 10.5 (Leopard)。 Your millage may vary for different versions, but it should be similar.您的 millage 可能因不同版本而异,但应该相似。

As noted on that forum post, you should also be aware that Time Machine automatically excludes the /home directory and does not back it up .如该论坛帖子所述,您还应该知道Time Machine 会自动排除/home目录并且不会对其进行备份


One note of warning, make sure to back up your /home directory manually before doing a system update.一个警告注意事项,请确保在进行系统更新之前手动备份您的/home目录。 I believe one of the updates I did (from 10.6 to 10.7 for example) wiped out what I has stored in /home without warning.我相信我所做的其中一项更新(例如从 10.6 到 10.7)在没有警告的情况下清除了我存储在/home中的内容。 I'm not 100% sure that's what happened, but it's something to be on the lookout for.我不是 100% 确定发生了什么,但这是需要注意的事情。

Putting it all together from the tips and hints above:根据上面的提示和提示将它们放在一起:

  • edit /etc/auto_master # comment out the line with /home in it.编辑/etc/auto_master #注释掉/home所在的行。

  • remount:重新安装:

    sudo automount -vc

  • make a softlink to the mac-ified dir:建立到 mac 化目录的软链接:

    sudo ln -s $HOME /home/$USER

At that point, your paths should match-up to your production paths.那时,您的路径应该与您的生产路径相匹配。 env vars will still point to /Users/xxxx , but anything you hard-code in a path in your .bashrc --or say, in ~/.pip/pip.conf -- should be essentially equivalent. env vars 仍将指向/Users/xxxx ,但是您在.bashrc中的路径中硬编码的任何内容——或者说,在~/.pip/pip.conf ——本质上应该是等效的。 Worked for me.为我工作。

re: "The real goal is to have all the files on the development Mac have the same filepath from the / root of the directory tree as the production server."回复: “真正的目标是让开发 Mac 上的所有文件与生产服务器的目录树的 / 根具有相同的文件路径。”

On production, my deploy work might happen in /opt/projects/projname , so I'll just make sure my account can write into /opt/projects and go from there.在生产环境中,我的部署工作可能发生在/opt/projects/projname中,因此我将确保我的帐户可以写入/opt/projects并从那里开始。 I'd start by doing something like this:我会先做这样的事情:

sudo mkdir /opt/projects sudo chown $USER /opt/projects mkdir /opt/projects/projname cd /opt/projects/projname

With LVM, I'll set a separate partition for /opt/ , and write app data there instead of $HOME .使用 LVM,我将为/opt/设置一个单独的分区,并在那里而不是$HOME写入应用程序数据。 Then, I can grow the /opt file system in cases where I need more disk space for a project (LVM is your friend.)然后,如果项目需要更多磁盘空间(LVM 是你的朋友),我可以增加/opt文件系统。

I tried it on Yosemite (OS X 10.10.1) the sudo automount -vc didn't work, I had to use sudo umount /home .我在优胜美地 (OS X 10.10.1) 上试过sudo automount -vc没有用,我不得不使用sudo umount /home

Therefore my workflow would be:因此我的工作流程是:

# comment out line starting with /home sudo vi "+g/^\/home/s/\//#\//" "+x" /etc/auto_master sudo umount /home # link actual home directory (/Users/<user>) to new 'home' (/home/<user>) ln -s $HOME /home/$USER # comment out line starting with /home sudo vi "+g/^\/home/s/\//#\//" "+x" /etc/auto_master sudo umount /home # link actual home directory (/Users/<user>) to new 'home' (/home/<user>) ln -s $HOME /home/$USER

I adapted the previous solutions to Big Sur (macOS 11.2), which is a bit more complicated due to the APFS file system changes.我将以前的解决方案改编为 Big Sur (macOS 11.2),由于 APFS 文件系统的变化,它有点复杂。 I managed to change /home by following these steps:我按照以下步骤设法更改了/home

  1. As recommended by Alan W. Smith, comment out the /home entry in /etc/auto_master .按照 Alan W. Smith 的建议,注释掉/etc/auto_master中的/home条目。
  2. As suggested by Marco Torchiano, run正如 Marco Torchiano 所建议的那样,运行
    sudo umount /home
  3. Since /home is currently a read-only link to /System/Volumes/Data/home , you have to change the latter.由于/home当前是/System/Volumes/Data/home的只读链接,您必须更改后者。 I did it with the following commands:我用以下命令做到了:
     cd /System/Volumes/Data/ sudo rmdir home sudo ln -s <some other directory> home

Why don't you just run MAMP and use the Sites directory?为什么不直接运行 MAMP 并使用 Sites 目录呢? You can develop off localhost and just have a bunch of aliases for your sites.您可以在 localhost 之外开发,并为您的网站设置一堆别名。 I'm not sure why you specifically need to use the home directory.我不确定您为什么特别需要使用主目录。


EDIT: Ok, I think you are going about solving your problem the wrong way.编辑:好的,我认为你正在以错误的方式解决你的问题。

If it's HTML paths you are worried about, the begin everything with a slash "/" which will default it to the home dierectory.如果它是您担心的 HTML 路径,那么一切都以斜杠“/”开头,这将默认为主目录。

If it's the references in your PHP, then you need to create a global (or similar) and set it as the root of your site.如果它是您的 PHP 中的引用,那么您需要创建一个全局的(或类似的)并将其设置为您站点的根目录。 Then you can reference everything from the global and when you move the site from dev to production all you need to change is the global.然后您可以引用全局的所有内容,当您将站点从开发转移到生产时,您需要更改的只是全局。

Trying in a round-about way to develop from /home because it looks more like the production server is a bad idea.尝试以一种迂回的方式从 /home 进行开发,因为它看起来更像是生产服务器是一个坏主意。

Install MAMP, create the global somewhere high in the hierarchy and start re-referencing.安装 MAMP,在层次结构的较高位置创建全局并开始重新引用。 It'll be less pain in the long run.从长远来看,它会减轻痛苦。

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

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