LAMP stack localhost folder permission issue is a pure hell for those of us who aren’t expert in the UNIX system. You’ve surely faced the issue when you can’t access localhost folder, unable to upload files through your web app etc.
If you’re still unable to fix this issue or every time you create new project folder you have to run
chown command, then this article is for you. After following this article you should no longer have the localhost folder permission issue.
I’ve used macOS Sierra while performing this fix and I believe this method should work for other macOS versions as well.
I’m assuming you’re using the default path for localhost which is:
If you have changed the default file path in apache config. Just replace the default path with your custom path while performing the commands below.
sudo chown -R www:www /Library/WebServer/Documents/
This command will add
www group as the directory owner. So you can perform the read and write tasks through web apps.
sudo chmod -R 775 /Library/WebServer/Documents/
Running this command will enable
www to perform any read & write tasks.
Add OS User To
At this point, you will see you can perform any directory based actions through your web apps. But every time you try to create a new folder inside localhost directory or try to edit any file, it will ask you for the administrator password. To fix this run the command below:
sudo dseditgroup -o edit -a
whoami-t user www
This command will add your local user to the
www group and you should be able to create, delete and edit any files or folder.
Feel free to let me know in the comment below if you still have the same issue after following this article.