Stairways Software Icon

Stairways Software

Excellence In Software For Over Ten Years – Only with a Mac

Working with Local Websites

Matthew asked me this, so I imagine others are not aware of this simple trick.

Suppose you have a local folder containing your website that you mirror up to your remote web host (using Interarchy, of course!). You probably preview your local web site to check changes. But what happens if you have absolute paths in your web site (eg /img/header.jpg)? These will break when you preview them locally.

But a simple trick is to create a symlink from /img on your harddisk (ie, in the root of your harddisk) to your local web folder‘s img directory. You can do this in the Terminal like:

ln -s /Users/peter/WebSite/img /img

Of course, this will only work for a single user on the machine, and only for a single web site (at a time!), but that is pretty common for many people. On Mac OS X, you do not even need root permissions to create the symlink (although you do need to be an admin user).

The same trick can be applied for other folders, like perhaps your css or javascript folders, that tend to be referenced by absolute paths from many pages.

Of course, relative paths are preferred in general, but that is not always easy/simple, and this trivial solution can help in those cases.

Posted Sunday, July 23, 2006. Permalink. 2 Comments.

Comments

This is a great trick to keep in your back pocket, but if you're doing any amount of web preflighting on the Mac, it would be a shame to overlook the default installation of Apache. By turning on Personal Web Sharing, you can pop your web pages and content into /Library/WebServer/Documents and browse them via http://localhost.

In addition to the "pseudo-root" provided by apache, a bunch of other things will "just work" provided your web host is also apache-based.

Posted Monday, July 24, 2006 05:26 AM by Daniel Jalkut.

If you're not logged in as root, it's probably best to set up test sites in your own 'Sites' folder (it's in your Home folder) like this: ~/Sites/test-site/ and make the test-site folder mimic the directory structure of your host, with a 'cgi-bin' and 'html' folders.

You'll need to read up on it (until I get my easy guide up and running!) but, with a few simple changes, you can then use Apache's Virtual Hosts by editing httpd.conf - you have to open it using Terminal by going to /private/etc/httpd/ - make a backup first! Then run the site (and any number of others under different names) just as it will be on the actual server, with a site root, CGI and other options enabled. You simply 'point' the Virtual Host to your 'test-site' folder.

Even for one site, it's good to use an include to the bottom of httpd.conf that tells Apache to bring in your Virtual Host directives from a separate file (Apple updates can disable custom httpd.conf files, but they can be restored). I keep my virtual hosts in an httpd folder under my user's Library folder:

/Users/MYLOGINHERE/Library/httpd/myhosts.conf

You then use NetInfoManager to add a 'browser-freindly' name for each test site as a new 'machine', using a name like 'test-site.local' (you can call it anything, and it doesn't have to have an extension, just alpha-numerics, underscores and dashes). You can then type this 'local' address into a browser. I use 'domain-name.lc' (the actual domain name, then 'lc' for 'local'). Don't follow non-OS X instructions to edit the 'hosts' file - NetInfo Manager does that automatically.

Site root addresses will then work fine - I use them when testing locally all the time.

Posted Friday, August 25, 2006 04:52 AM by Dave Everitt.

Post Comment

Name: (optional)
URL: (optional)
Email: (optional, not published)
   
CAPTCHA: seven two nine eight (required)
  To prove you are human, please enter the number as digits (ie, 1-9).
Comment:
  You can use some HTML tags such as <b>, <i>, and <a href="">.
We reserve the right to remove any offensive or inappropriate comments.
Due to spam issues, comments are initially invisible until we review them,
you can see them (background red) and we can see them, but no one else.

Comment Preview

None yet.

Buy Now

User Database

Stairways