In case you develop Magento 2 project (or some other web application) on local Yosemite and sometimes you see 403 Forbidden error you are reading right article.
So, during my Magento 2 development and other projects I was getting an error which annoyed me every time. The error says:
You don’t have permission to access .htaccess on this server.
I’ve spent hours debugging my apache2 configurations (httpd-vhosts.conf, user.conf, httpd.conf), file permissions, maximum allowed opened files in the system. My initial guess was that Yosemite system limits amount of files opened. That was I saw in error (Too many files opened). I increased this limit, however error did show again. Randomly.
Of course when you develop with Magento 2 having lots of files you could also think that it can’t handle big amount of files. That was I thought.
How to fix
In order to resolve the 403 Forbidden problem you have to adjust permissions for user which is used to run localhost server.
1. Find your username with this command:
2. Then navigate and check if you have config for this user or create if doesn’t exist:
cd /etc/apache2/user/ touch <username>.conf
Where username is an user name used to run Apache server.
3. Add the following configuration (note that this is only for Yosamite):
sudo vi /etc/apache2/user/<username>.conf
Add the following content:
<Directory "/Users/<username>/Sites/"> AddLanguage en .en LanguagePriority en fr de ForceLanguagePriority Fallback Options FollowSymlinks Indexes MultiViews AllowOverride All Order allow,deny Allow from localhost Require all granted </Directory>
4. Add lines in the
/etc/apache2/httpd.conf configuration file:
sudo vi /etc/apache2/httpd.conf
Check and uncomment the line:
5. In the
httpd-userdir.conf file ensure to uncomment line:
6. Restart Apache server
sudo /usr/sbin/httpd -k restart
Enjoy developing your Magento 2 projects.
Max with his team of Magento enthusiasts won the Best Magento 1 to Magento 2 Migration Award at the Magento Imagine 2017. As CEO at Pronko Consulting, he is actively working with Magento 2, delivering superior customer experience. As one of the most famous developers on a market and in the Magento Community, he launched Magento 2 blog, Magento DevChannel – YouTube channel in 2017 where he shares his knowledge, experience and the best practices in the Magento field.
Subscribe to my Magento 2 tips and tutorials content.
Every week I send an interesting email directly to your inbox