12

I'm trying to set up a virtual host on my Mac OS X 10.7 Installation. I'm using VirtualHostX to manage my /etc/hosts and httpd-vhosts.conf file. Currently, my httpd-vhosts.conf file looks like this:

NameVirtualHost *:80

<Directory "/Users/yuval/Sites/mysite/">
Allow From All
AllowOverride All
</Directory>
<VirtualHost *:80>
    ServerName "mysite.dev"
    DocumentRoot "/Users/yuval/Sites/mysite"
</VirtualHost>

and my /etc/hosts files has this in it:

# VHX START
127.0.0.1 mysite.dev
fe80::1%lo0 mysite.dev
# VHX STOP

I activated Web Sharing under System preferences, and I know apache is running. However, when I navigate to either 127.0.0.1 or to mysite.dev, I get the following:

Forbidden

You don't have permission to access / on this server.

My permissions on /Users/yuval/Sites/mysite are 755. Trying to change them to 777 didn't help either. Note that this is happening with any folder I choose -- I do not have an .htaccess file in /Users/yuval/Sites/mysite.

Update: Checking the apache error, these are the logs that appear:

[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
    access to / denied
[Fri Dec 09 17:59:27 2011] [error] [client 127.0.0.1] (13)Permission denied:
    access to /favicon.ico denied

It seems pretty obvious that the vhosts + hosts code is doing its job in actually determining that the address exists, but for some reason this isn't working. Any ideas?

sarnold
  • 102,305
  • 22
  • 181
  • 238
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175

2 Answers2

11

Make sure an index.html file is in the /Users/yuval/Sites/mysite/ directory.

OR enable directory indexing:

<Directory "/Users/yuval/Sites/mysite/">
  Options +Indexes
  Allow From All
  AllowOverride All
</Directory>

You can also set the DirectoryIndex option to look for default files other than index.html: http://httpd.apache.org/docs/current/mod/mod_dir.html

Edit

Saw your error message - this doesn't look like a directory index problem.

Try chmod 755 on the /Users/yuval directory as mentioned in this ServerFault answer: https://stackoverflow.com/a/1241319/212700

Also check for any .htaccess files in the /Users/yuval/Sites/ directory as Apache will check those as well.

Community
  • 1
  • 1
leepowers
  • 37,828
  • 23
  • 98
  • 129
  • Thank you for the suggestions. There was an index.php file in the directory, but I went ahead and added a .html file. Still nothing. I then enabled Indexes and restarted apache, but still no luck. Any other ideas? – Yuval Karmi Dec 10 '11 at 02:07
  • 1
    You've hit the issue right on its head! Parent directory permission issue it was indeed! Thank you so very much! – Yuval Karmi Dec 10 '11 at 02:29
  • chmod 755 on parent folder is the way. – Matthieu Mar 12 '13 at 09:33
6

The only thing I had to do was re-point to my custom vhost directory (and restart apache.)

I tried to point to ~/Sites/vhosts instead of /Users/[Username]/Sites/vhosts where I keep all my .conf files, so there was a configuration error. I was looking for the apache logs and learned from the apache docs about httpd -S which told me exactly where the configuration problems were.

Lots of misinformation in blogs on the net so Im posting this here for apache noobs like me.

httpd -S
# fix the issues
sudo apachectl restart
Shanimal
  • 11,517
  • 7
  • 63
  • 76