Magento 2 – Server Unable to Read .htaccess File, Denying Access to Be Safe

.htaccessapachemagento2permissions

My Magento 2 development system started, at (seemingly) random, to display the following error for all my frontend JS files

Server unable to read htaccess file, denying access to be safe

This error persists even after I (temporarily) chmod 777 all my .htaccess files

$ find pub -name .htaccess -exec ls -ld '{}' \;
-rwxrwxrwx  1 alanstorm  staff  5544 Nov 20 10:44 pub/.htaccess
-rwxrwxrwx  1 alanstorm  staff  72 Nov 20 10:44 pub/errors/.htaccess
-rwxrwxrwx  1 alanstorm  staff  3389 Nov 20 10:44 pub/media/.htaccess
-rwxrwxrwx  1 alanstorm  staff  31 Nov 20 10:44 pub/media/customer/.htaccess
-rwxrwxrwx  1 alanstorm  staff  31 Nov 20 10:44 pub/media/downloadable/.htaccess
-rwxrwxrwx  1 alanstorm  staff  31 Nov 20 10:44 pub/media/import/.htaccess
-rwxrwxrwx  1 alanstorm  staff  88 Nov 20 10:44 pub/media/theme_customization/.htaccess
-rwxrwxrwx  1 alanstorm  staff  3300 Nov 20 10:44 pub/static/.htaccess

What's the deal?

Best Answer

Be sure to check the permissions on the parent directory. For example, if you're seeing this error when you request

http://magento-2-with-keys.dev/pub/static/frontend/Magento/luma/en_US/Magento_Customer/js/customer-data.js

Make sure your permissions are right on

ls -ld pub/static/frontend/Magento/luma/en_US/Magento_Customer

$ ls -ld pub/static/frontend/Magento/luma/en_US/Magento_Customer
drwxrwx---  8 alanstorm  staff  272 Dec 14 16:25 pub/static/frontend/Magento/luma/en_US/Magento_Customer

Magento 2's core seems a little inconsistent about umasks and permissions, and created folders will often be missing the execute permission for the global permission set. I'm guessing the core team doesn't use MOD_PHP much, and opts instead for one of PHP's FastCGI implementations.

Related Topic