Serve web pages via Apache from a USB key drive

May 27, '04 08:29:00AM

Contributed by: rroberts

For web developers, Mac's Apache web server won't automatically serve web-related files that reside on a USB key drive. Any effort to do so results in an Apache error page. Read the rest of the hint for details on how to make Apache happily serve up pages from a USB key drive.

By default, the USB key drive is usually named something like "NO NAME," so change it to something more convenient - short, no spaces, and note that the name must be uppercase. As an example, let's name the key drive BOB. The actual unix location of key drive BOB is /Volumes. Apache won't serve anything from there, so you need to go into your Sites directory and create a unix-style symbolic link to BOB. Do not create a Mac alias, because it's not the same thing. In Terminal.app, enter the following commands (don't type the % - it represents your unix prompt):

% cd Sites
% ln -s /Volumes/BOB BOB
Next you have to edit your Apache user config file, located in /etc/httpd/users. For now, let's say your shortname is xyz. The default xyz.conf file in that directory looks something like this:
<Directory "/Users/xyz/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
So, still in Terminal.app, type the following commands (don't type the ## or anything after them; that's just a comment to explain what's happening with each command):
% cd /etc/httpd/users                ## Change into the directory
% sudo cp xyz.conf xyz.conf.original ## Make a backup of your config file
% sudo vim xyz.conf                  ## Use vim (or your editor of choice)
Edit your config file to look like this, (replace xyz with your short username):
<Directory "/Users/xyz/Sites/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/Users/xyz/Sites/BOB">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
After saving and closing your config file, restart Apache by typing sudo apachectl graceful. Now you can access the key drive in a browser at this URL (replace xyz with your short username, of course): http://127.0.0.1/~xyz/BOB/ If you have PHP enabled and running, you can test PHP locally as well. Hooray!

Comments (1)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040524223447899