Magento 2 – Static Files Present but Showing 404 Error

apachemagento2static-content

I installed Magento 2 in my local environment and executed each command:

php bin/magento cache:clean

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

But when I hit the site from browser, it shows following errors:

http://127.0.0.1/m2shop.drberg.com/pub/static/version1513076694/frontend/Magento/luma/en_US/css/styles-l.css net::ERR_ABORTED
(index):16 

http://127.0.0.1/m2shop.drberg.com/pub/static/version1513076694/_cache/merged/9de8797d0c615276fc794278a0af8df2.css net::ERR_ABORTED
(index):21 

http://127.0.0.1/m2shop.drberg.com/pub/static/version1513076694/_cache/merged/c0b5661e7cfc4d3e29c8fc8495e4d56e.js net::ERR_ABORTED
(index):144 

Uncaught TypeError: require.config is not a function
    at (index):144
(anonymous) @ (index):144
(index):243 

http://127.0.0.1/m2shop.drberg.com/pub/static/version1513076694/frontend/Magento/luma/en_US/images/logo.svg 404 (Not Found)
(index):18 

http://127.0.0.1/m2shop.drberg.com/pub/static/version1513076694/frontend/Magento/luma/en_US/css/print.css net::ERR_ABORTED

All these files are actually present in the directory but Magento is not unable to read those files. why?

Best Answer

First, make sure apache “rewrite_module” is enable and then restart the server.

If this hasn't worked. Then do following steps:

  1. Edit the file /etc/apache2/apache2.conf.
  2. Find this code:
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
  1. Change "AllowOverride None" to "AllowOverride All".
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted 
</Directory>
  1. Restart apache2.
Related Topic