Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm using it to do web development/testing before publishing files to my production host.

On the production host my site's doc root is under the home directory (e.g. /home/stimulatingpixels/public_html) and I'd like to duplicate that location on the 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.

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).

So, the question, is there anyway to safely use /home on a Mac either Leopard or 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.)

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. 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.

Another Update: The other reason that I forgot to mention earlier for this is setting up .htaccess paths when using basic authentication. 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.

like image 385
Alan W. Smith Avatar asked Sep 01 '09 14:09

Alan W. Smith


2 Answers

NOTE: As of 2015, I no longer use or recommend this method. Instead I use Vagrant to setup virtual machines for dev and testing. 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.

In order to reclaim the /home directory, edit the /etc/auto_master file and comment out (or remove) the line with /home in it. You'll need to reboot after this for the change to take effect (or, per nilbus' comment, try running sudo automount -vc). This works with Mac OS X 10.5 (Leopard). Your millage may vary for different versions, but it should be similar.

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.


One note of warning, make sure to back up your /home directory manually before doing a system update. 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. I'm not 100% sure that's what happened, but it's something to be on the lookout for.

like image 196
Alan W. Smith Avatar answered Sep 29 '22 11:09

Alan W. Smith


Putting it all together from the tips and hints above:

  • edit /etc/auto_master # comment out the line with /home in it.

  • remount:

    sudo automount -vc

  • make a softlink to the mac-ified dir:

    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. 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."

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. 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. Then, I can grow the /opt file system in cases where I need more disk space for a project (LVM is your friend.)

like image 27
KurtB Avatar answered Sep 29 '22 12:09

KurtB