Saturday, September 6, 2008

How to add an Apache directory alias in Mac OS X 10.5 (Leopard)

Another point that I spent a lot of time trying to do was to make an Apache directory alias. The first thing that you have to know is that all directories in the path for the target directory must be with at least permission to read. This was the point that I spent more time. I was trying to make an alias to the directory ~/Desktop/quickstart and the Desktop directory had no read permission for group and others, so that was the problem.
  • You have to edit /etc/apache2/users/{username}.conf and add the following lines:
<IfModule alias_Module>
Alias /your_project /Users/{username}/Desktop/your_project
</IfModule>

<Directory "/Users/{username}/Desktop/your_project">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
<Directory>

  • Save the file and restart apache server.

5 comments:

Felix said...
This comment has been removed by the author.
Felix said...

Hi,
I could need some help. Edited the felix.conf file to http://codeviewer.org/view/code:1121. I removed the tags because without them I get a 403 error instead of 404.
403 means Permission denied and I don't know how to change the permission correctly:
drwxr-xrwx 4 felix staff 136 15 Aug 18:42 test

I try to access the directory via http://localhost/Drivess

Thank you very much

guneves said...
This comment has been removed by the author.
guneves said...

most important part is:
"all directories in the path for the target directory must be with at least permission to read."

So you know:
$ represents terminal (should not be typed)
gus represents my user folder

So for example: I wanted to add access to:
/Users/gus/Documents/Griffith/sem6/2622ICT/Lab exercises/

So I had to:
$ chmod 755 /Users/
$ chmod 755 /Users/gus/
$ chmod 755 /Users/gus/Documents/
... and so on

I have also done:
$ chmod 755 /Users/gus/Documents/Griffith/sem6/2622ICT/Lab exercises/*
as I want all folders inside that folder to be visible.
This way I can open any version I have there (each week I have a new lab done).

I have also enabled symlinks and then I have actually used the symlink in my alias.
Example:
$ cd /Users/gus/Sites
$ ln -s /Users/gus/Documents/Griffith/sem6/2622ICT/Lab\ exercises/ flickmee

and then my alias was defined as:
Alias /flickmee "/Users/tavin/Sites/flickmee"

Followed by:
<Directory "/Users/tavin/Sites/flickmee">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Hope this helps other people.
Google for macos x apache symlinks for mor info on symlinks

PS: Had to repost because the chars < > were interpreted as html.

Cheers!

guneves said...

Something I forgot to mention:
You may need to call sudo before some commands (so you can do that as root). Terminal will require you user password if using sudo.

and also, to restart apache you can use:
sudo apachectl graceful

Cheers! XD