June 29, 2003

Virtual Hosts and Symbolic Links

Last night I finagled my way into setting up the Apache web server on my laptop to serve multiple sites from multiple directories. This means I that I can keep the various projects I’m working on better organized and it helps to facilitate synchronization between the local test site and the live site. The only part I haven’t been able to figure out is how to get the local virtual hosts to follow symbolically linked directories but it’s not that big of an issue. If you’re interested in setting up this functionality on your own Mac OS X installation, you can read all about it on Evolt.

Previous Post

Comments

Brian Poulsen

Uhm … Why make symbolic links to virtualhosts? I just have a www folder in which different projects are. I just make virutalhosts to the folders and gives them local network names to access through the browser.

Walt Dickinson

I’m not making symbolic links to the virtual hosts. I’m doing excatly what you’re doing. I just have a symbolic link within one of my virtual host directories which I’d like the host to follow. But it’s not. Like I say, not a huge deal, just can’t figure out why it won’t work.

I could be wrong, but check your httpd.conf file. Where you define the directory permissions for your virtual hosts you have some “Options” defined you may need to add “FollowSymLinks” to that statement. Take a look at the docs on Apache’s website.

Walt Dickinson

Thanks for the feedback David. I had tried setting that option for the directory of my virtual host. No luck. I suspect I’m still missing something or perhaps the syntax isn’t correct. Here’s an excerpt from my httpd.conf file:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1> DocumentRoot /Library/WebServer/Documents/ ServerName 127.0.0.1 </VirtualHost>

<VirtualHost 127.0.0.1> DocumentRoot /Library/WebServer/iwalt.com/ ServerName www.iwalt.walt

<Directory “/Library/WebServer/iwalt.com/”> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory>

</VirtualHost>

Hmm, the syntax looks right. I am assuming your permissions are set correctly for the directory your symbolic link points to. What does Apache say when you attempt to browse to that directory?

Walt Dickinson

Here’s what it says:

Not Found The requested URL /foo/ was not found on this server.

Also: Accessing the symbolically linked directory through the non-virtual server works fine which leads me to agree that the permissions are set correctly.

It seems to me the virtual host and directory setup within your .conf file are right. If the error was a directory/file permssion problem from the OS I think it would say FORBIDDEN. Does the Apache error or access log have anything to say when you attempt to acces that directory from your virtual host?

Walt Dickinson

The access log indicates that a 404 was sent. The error log indicates that the file does not exist. Pretty much what you would expect and not very helpful.

Thanks for all your thoughts on this btw. Much appreciated.

I’m at a lose as to why this isn’t working for you. I am sure I am overlooking something. You said browsing to the directory through the non-virtual host works. When you do it that way is it still a symbolic link or is that browsing to the true directory? Have you tried browsing through the symbolic link with finder or through the terminal to verify that the link infact works. I could see a not found error occuring if there was an issue with the symbolic link itself.

Walt Dickinson

Solved. In a nutshell, all I wanted to do was to move the default Apache files into its own virtual server. Part of the Apache installation is a symbolic link to the documentation. This soft link is called “manual”. The default Apache httpd.conf file for Mac OS X has a bit which needs to be commented out if you’re trying to do what I did:

Alias /manual/ “/Library/WebServer/Documents/manual/”

<Directory “/Library/WebServer/Documents/manual”> Options Indexes FollowSymlinks MultiViews AllowOverride None Order allow,deny Allow from all </Directory>

David Selders

Glad you got it figured out.