1

I'm trying to get LAMP working on OSx Lion and am having a little trouble.

Have Apache, MySQL, and PHP set up and working just fine. Have turned on "Website" under sharing in Settings. Removed the original ~/user_name/Sites folder and created a symbolic link of Sites to a directory withint ~/user_name.

Now when I try to run http://localhost/~user_name I get:

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

Where and how do I change these permissions?

5
  • 1
    I highly recommend MAMP, which is like LAMP but specifically for the Mac. I've used it a lot with no permissions problems. Dec 10, 2011 at 18:21
  • Apache doesn't follow symlinks by default. But before we try to solve that one, let's first get the basic setup right. Can you recreate the ~/Sites folder, create at least one html file in it and try to access it via http://localhost/~user/the-file.html?
    – nohillside
    Dec 11, 2011 at 13:48
  • Thanks, @patrix. That works just fine. Deleted the sym links and I can access localhost/~user/test.html just fine.
    – David
    Dec 11, 2011 at 14:42
  • Ended up getting this to work by changing the following in httpd.conf <Directory /> Options -Indexes Includes FollowSymLinks MultiViews AllowOverride None Options Order allow,deny Allow from all </Directory>
    – David
    Dec 11, 2011 at 15:56
  • Just stick with the default document root (/Library/WebServer/Documents) and create a symlink to it in your home folder. Aug 12, 2012 at 23:46

3 Answers 3

3

When accessing websites on your "localhost", there are several permissions which are required. The localhost content may be in your Sites directory, in which case, these commands may help prevent any "Forbidden" messages.

Ensure the Users directory allows read directory access:

cd /
sudo chmod -v 755 Users

Ensure the username directory allows read directory access:

cd Users
sudo chmod -v 755 username

Ensure your Sites directory allows read directory access:

cd ~
chmod -v 755 Sites

Every subdirectory of Sites needs read access:

cd ~/Sites
find ~/Sites -type d -print -exec chmod 755 {} \;

Every file in Sites and subdirectories needs read access:

cd ~/Sites
fing ~/Sites -type f -print -exec chmod 644 {} \;

Apache uses the _www group so, to give Apache full access to everything in the Sites directory, set the extended attributes with this:

chmod -R +a "group:_www allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" ~/Sites
1

Assuming few people ever use OS X in a production environment, it is nice to let apache do whatever it wants with the document root. You can do this with the "inheritance" feature of ACL's:

sudo chmod -R +a "group:_www allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" /Library/WebServer/Documents/

The above command will give the default apache group full read/write access to everything in the default document root and apply "inheritance" flags so any new files/directories created will also be writable by apache, even if apache did not create them.

I also like to run this command:

sudo chmod -R +a "group:staff allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" /Library/WebServer/Documents/

Which will give "staff" users (basically that means all "real" users) full access to everything, even files created by apache.

-1

You could use chmod to set the permissions on the folder where your site is. Make sure the user Apache is running as may read anything in that folder.

  1. open Terminal
  2. cd /path/to/website
  3. chmod -r 644 .

That should do it. Be aware that this will make your php source files readable to anyone.

3
  • Those permissions (466) are really really wrong. They allow the user read-only access, but everyone else read+write access. Except that since they don't allow anyone execute (aka search) access to the directories, nobody can actually access the files inside (just read & maybe write their names). Dec 11, 2011 at 7:02
  • I think you mean chmod 644
    – Andrew Vit
    Dec 11, 2011 at 9:44
  • 1
    644 makes more sense, but still leaves out execute access (needed for directories). chmod -R u=rwX,go=rX . would work, because chmod treats "X" permission as "x if it makes sense". Dec 11, 2011 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .