4

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?

  • What are you running your local environment with? Apache or NGINX? – Matt Antley Dec 12 '17 at 11:43
  • 1
    i am running Apache. – umair ayub Dec 12 '17 at 11:44
7

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.
  • Perfect +1 ...... – Vivek Mar 9 at 18:31
  • Perfect, Thanks – Ravi Jun 15 at 9:30
1

I have same issue and its occurs when i am was deleted pub/static folder.

And its Resolved after placing missing .htaccess file in static folder

<IfModule mod_php5.c>
php_flag engine 0
</IfModule>

<IfModule mod_php7.c>
php_flag engine 0
</IfModule>

# To avoid situation when web server automatically adds extension to path
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove signature of the static files that is used to overcome the browser cache
    RewriteRule ^version.+?/(.+)$ $1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* ../static.php?resource=$0 [L]
</IfModule>

############################################
## setting MIME types

# JavaScript
AddType application/javascript js jsonp
AddType application/json json

# HTML

AddType text/html html

# CSS
AddType text/css css

# Images and icons
AddType image/x-icon ico
AddType image/gif gif
AddType image/png png
AddType image/jpeg jpg
AddType image/jpeg jpeg

# SVG
AddType image/svg+xml svg

# Fonts
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf
AddType application/x-font-otf otf
AddType application/x-font-woff woff
AddType application/font-woff2 woff2

# Flash
AddType application/x-shockwave-flash swf

# Archives and exports
AddType application/zip gzip
AddType application/x-gzip gz gzip
AddType application/x-bzip2 bz2
AddType text/csv csv
AddType application/xml xml

<IfModule mod_headers.c>

    <FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$>
        Header append Cache-Control public
    </FilesMatch>

    <FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$>
        Header append Cache-Control no-store
    </FilesMatch>

</IfModule>

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On

    # Data
    <FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$>
        ExpiresDefault "access plus 0 seconds"
    </FilesMatch>
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType text/csv "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
    ExpiresByType application/zip "access plus 0 seconds"
    ExpiresByType application/x-gzip "access plus 0 seconds"
    ExpiresByType application/x-bzip2 "access plus 0 seconds"

    # CSS, JavaScript, html
    <FilesMatch \.(css|js|html)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/html "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"

    # Favicon, images, flash
    <FilesMatch \.(ico|gif|png|jpg|jpeg|swf|svg)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"

    # Fonts
    <FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$>
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-otf "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"

</IfModule>

Note : - Manually by clearing the pub/static and var/view_preprocessed directories and subdirectories except for pub/static/.htaccess.

To clear the pub/static directory of all files except .htaccess (which is a hidden file), enter the following command:

rm -R pub/static/*
  • perfect answer! +1 made my day :) – SagarPPanchal Nov 6 '18 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.