Magento 2 403 Forbidden Error Fix

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:
[php]
whoami
[/php]

2. Then navigate and check if you have config for this user or create if doesn’t exist:
[php]
cd /etc/apache2/user/
touch <username>.conf
[/php]
Where username is an user name used to run Apache server.

3. Add the following configuration (note that this is only for Yosamite):
[php]
sudo vi /etc/apache2/user/<username>.conf
[/php]

Add the following content:

[php]
<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>
[/php]

4. Add lines in the /etc/apache2/httpd.conf configuration file:
[php]
sudo vi /etc/apache2/httpd.conf
[/php]

Check and uncomment the line:

[php]
Include /private/etc/apache2/extra/httpd-userdir.conf
[/php]

5. In the httpd-userdir.conf file ensure to uncomment line:
[php]
Include /private/etc/apache2/users/*.conf
[/php]

6. Restart Apache server
[php]
sudo /usr/sbin/httpd -k restart
[/php]

Enjoy developing your Magento 2 projects.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *