Magento 2 403 Forbidden Error Fix

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:

  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
  4. Add lines in the /etc/apache2/httpd.conf configuration file:
    sudo vi /etc/apache2/httpd.conf

    Check and uncomment the line:

    Include /private/etc/apache2/extra/httpd-userdir.conf
  5. In the httpd-userdir.conf file ensure to uncomment line:
    Include /private/etc/apache2/users/*.conf
  6. Restart Apache server
    sudo /usr/sbin/httpd -k restart

Enjoy developing your Magento 2 projects.

magento 2 apache

Related Articles


Next Article Previous Article

LinkedIn Twitter Facebook