13

I have successfully installed Magento 2 on the wamp server but I'm having a slight issue of loading the admin page as it is giving me a 404. Also, when loading its homepage the default theme that is luma in my case doesn't apply and instead gives me the following errors:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/mage/calendar.css     
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-m.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-l.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/print.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/images/logo.svg    
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-m.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-l.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/requirejs/require.js 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/print.css     
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/mage/requirejs/mixins.js 
Failed to load resource: the server responded with a status of 404 (Not Found)
requirejs-config.js:602 Uncaught ReferenceError: require is not defined
127.0.0.1/:24 Uncaught ReferenceError: require is not defined
127.0.0.1/:26 Uncaught ReferenceError: require is not defined
Purushotam Sharma
  • 1,657
  • 2
  • 26
  • 59
Saharcasm
  • 131
  • 1
  • 1
  • 3
  • check answer here : http://magento.stackexchange.com/questions/91087/magento-2-admin-url-not-working-and-loaded-frontend-is-all-messy/120109#120109 – Anil Suthar Jun 09 '16 at 08:21

7 Answers7

18

Css and js will created at run time in pub/static folder In first time,if css and js missing then run below command

if you are using windows: php bin\magento setup:static-content:deploy

if using linux of 'git bash': php bin/magento setup:static-content:deploy

Anand Ontigeri
  • 909
  • 2
  • 10
  • 26
  • Also, make sure you enabled Apache server rewrites – Steve Johnson Jan 07 '16 at 14:42
  • Would appreciate if you could break down the steps. How to run the Windows command? How to know if it actually worked? – Mohammed Joraid Jun 28 '17 at 19:49
  • It's worth nothing that if you've downloaded the source from github and you install via the browser you will need to enable developer mode. The above command will complain that you don't need to run setup:static-content:deploy in developer mode so ensure you append -f to the above command. If you've set a different language other than en_US you will also need to supply those: php bin\magento setup:static-content:deploy -f en_US en_GB – BugHunterUK Feb 17 '20 at 22:53
16

I was also facing this problem. Admin gives 404 error and frontend didn't attach css(i.e. Luma didnot showing in proper format..).so i did these steps to solve these both problems in magento 2. 1)go to terminal and run this command

sudo gedit /etc/apache2/apache2.conf

And change:-

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted

To

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

chnage only AllowOverride none to All

and

2) go to terminal and run command :-

sudo a2enmod rewrite
sudo service apache2 restart

Then give the permission to your var,pub and app/etc. and then go to your admin and frontend it works properly.

Amit Bera
  • 77,456
  • 20
  • 123
  • 237
Sushant Kumar
  • 191
  • 1
  • 2
8

For those who are using wamp server, then run these commands in your CLI.

C:\wamp\bin\php\php5.5.12>php.exe
C:\wamp\www\\bin\magento setup:static-content:deploy

fmsthird
  • 4,592
  • 4
  • 17
  • 41
MaYaNk
  • 1,730
  • 1
  • 16
  • 27
6

I was also facing this issue. After fresh install of magento 2 with demo data when navigating to the frontend and backend too in localhost. Got MIME type mismatch errors for calendar.css and require.js. Nothing worked for me unless deployed the static content through

php bin/magento setup:static-content:deploy

in git bash and while it is default mode.

Umar Yousaf
  • 343
  • 3
  • 8
3

I was facing the same problem, I used Alan Storm solution from that article - http://alanstorm.com/magento_2_adding_frontend_files_to_your_module

use that command in ssh

find /path/to/magento2/pub/static -exec chmod 777 '{}' +
find /path/to/magento2/var/ -exec chmod 777 '{}' + 
electroid
  • 358
  • 4
  • 15
3

Enable URL rewrites.

1) Open terminal in Ubuntu and execute these commands:

sudo a2enmod rewrite

sudo service apache2 restart

2) Make sure you have the .htaccess file in your root directory of magento, if there is no .htaccess file copy the /pub/.htaccess file and paste it in the root directory

3) Open /etc/apache2/apache2.conf file using following commands:

sudo nano /etc/apache2/apache2.conf

And change the following lines of code:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted

To

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Save and close the file by Ctrl + X

  • Restart the apache

    sudo service apache2 restart

Usman Yousaf
  • 621
  • 7
  • 16
0

If All the Required Static Files present in {root}/pub/static directory then please make .htaccess file is present in {root}/pub/static dir or not. if .htaccess file is missing at {root}/pub/static dir then create a .htaccess file and paste below code

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

<IfModule mod_php.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

## you can put here your pub/static folder path relative to web root
#RewriteBase /magento/pub/static/

# 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]
# Detects if moxieplayer request with uri params and redirects to uri without params
&lt;Files moxieplayer.swf&gt;
    RewriteCond %{QUERY_STRING} !^$
    RewriteRule ^(.*)$ %{REQUEST_URI}? [R=301,L]
 &lt;/Files&gt;

</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 AddType image/webp webp AddType image/avif avif AddType image/avif-sequence avifs

SVG

AddType image/svg+xml svg svgz

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

Manifest

AddType application/manifest+json webmanifest

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>

&lt;FilesMatch .*\.(ico|jpg|jpeg|png|gif|svg|webp|avif|avifs|js|css|eot|ttf|otf|woff|woff2|html|json|webmanifest)$&gt;
    Header append Cache-Control public
&lt;/FilesMatch&gt;

&lt;FilesMatch .*\.(zip|gz|gzip|bz2|csv|xml)$&gt;
    Header append Cache-Control no-store
&lt;/FilesMatch&gt;

</IfModule>

<IfModule mod_expires.c>

############################################

Add default Expires header

http://developer.yahoo.com/performance/rules.html#expires

ExpiresActive On

# Data
&lt;FilesMatch \.(zip|gz|gzip|bz2|csv|xml)$&gt;
    ExpiresDefault &quot;access plus 0 seconds&quot;
&lt;/FilesMatch&gt;
ExpiresByType text/xml &quot;access plus 0 seconds&quot;
ExpiresByType text/csv &quot;access plus 0 seconds&quot;
ExpiresByType application/json &quot;access plus 0 seconds&quot;
ExpiresByType application/zip &quot;access plus 0 seconds&quot;
ExpiresByType application/x-gzip &quot;access plus 0 seconds&quot;
ExpiresByType application/x-bzip2 &quot;access plus 0 seconds&quot;

# Manifest
&lt;FilesMatch \.(webmanifest)$&gt;
    ExpiresDefault &quot;access plus 0 seconds&quot;
&lt;/FilesMatch&gt;
ExpiresByType application/manifest+json &quot;access plus 0 seconds&quot;

# CSS, JavaScript, html
&lt;FilesMatch \.(css|js|html|json)$&gt;
    ExpiresDefault &quot;access plus 1 year&quot;
&lt;/FilesMatch&gt;
ExpiresByType text/css &quot;access plus 1 year&quot;
ExpiresByType text/html &quot;access plus 1 year&quot;
ExpiresByType application/javascript &quot;access plus 1 year&quot;
ExpiresByType application/json &quot;access plus 1 year&quot;

# Favicon, images, flash
&lt;FilesMatch \.(ico|gif|png|jpg|jpeg|svg|svgz|webp|avif|avifs)$&gt;
    ExpiresDefault &quot;access plus 1 year&quot;
&lt;/FilesMatch&gt;
ExpiresByType image/gif &quot;access plus 1 year&quot;
ExpiresByType image/png &quot;access plus 1 year&quot;
ExpiresByType image/jpg &quot;access plus 1 year&quot;
ExpiresByType image/jpeg &quot;access plus 1 year&quot;
ExpiresByType image/svg+xml &quot;access plus 1 year&quot;
ExpiresByType image/webp &quot;access plus 1 year&quot;
ExpiresByType image/avif &quot;access plus 1 year&quot;
ExpiresByType image/avif-sequence &quot;access plus 1 year&quot;

# Fonts
&lt;FilesMatch \.(eot|ttf|otf|svg|woff|woff2)$&gt;
    ExpiresDefault &quot;access plus 1 year&quot;
&lt;/FilesMatch&gt;
ExpiresByType application/vnd.ms-fontobject &quot;access plus 1 year&quot;
ExpiresByType application/x-font-ttf &quot;access plus 1 year&quot;
ExpiresByType application/x-font-otf &quot;access plus 1 year&quot;
ExpiresByType application/x-font-woff &quot;access plus 1 year&quot;
ExpiresByType application/font-woff2 &quot;access plus 1 year&quot;
ExpiresByType font/opentype &quot;access plus 1 year&quot;
ExpiresByType font/truetype &quot;access plus 1 year&quot;

</IfModule>

Note: Magento 2.4.4.

if above .htaccess code not works. then try this .htaccess file code

Harsh Patel
  • 219
  • 1
  • 10