[Fixed] – “Failed to Load Resources” Error After Magento 2 Installation

Ever faced an issue of “Failed to load resource: the server responded with a status of 404 (Not found)” for CSS and Js after installing Magento 2 on Wamp server windows?

Meetanshi-Programmer

Try one of the below methods to get the solution:

Solutions for “Failed to Load Resources” Error After Magento 2 Installation:

Solution 1:

Give proper permissions, enable apache rewrite_module and refresh apache server.

chmod -R 777 MAGENTO_2_ROOT_DIRECTORY/

Run the following command from Magento root for fixing the frontend:

bin/magento setup:static-content:deploy

Clear var directory except .htaccess file and check admin.

If you get 404 page, there may be an issue of Symlink. Edit apache config file

Note: Implement this only if you are using apache.

sudo gedit /etc/apache2/apache2.conf

Replace the below code:

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

with:

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

Note: Change AllowOverride None to AllowOverride All

Restart apache sudo service apache2 restart and check admin. It fixes the admin 404 issue.
Moreover, make sure, you don’t leave /app/etc/ directory writeable.

Solution 2:

Css and js is created at run time in pub/static folder.

At first, if css and js is missing, run the below command:

For Windows:

binmagento setup:static-content:deploy

For Linux of ‘git bash’:

bin/magento setup:static-content:deploy

Solution 3:

Update the .htaccess file under /pub/static folder.

Open MAGENTO_DIR/pub/static/.htaccess and add the below code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pub/static/ # <- Add This

Instead, you can also disable static file signing by adding this record into the core_config_data table with this query:

INSERT INTO `core_config_data` VALUES (NULL, 'default', 0, 'dev/static/sign', 0);

Solution 4:

If you are using Magento 2.3.X version, this solution is for you:

Change the above foreach loop to run our Magento with no further issues on this:

#/vendor/magento/framework/View/Element/Template/File/Validator.php:139
foreach ($directories as $directory) 
{
    // Add this line
    $realDirectory = $this->fileDriver->getRealPath($directory);
    // and replace `$directory` with `$realDirectory`
    if (0 === strpos($realPath, $realDirectory)) 
    {
        return true;
    }
}

Hopefully, you are able to fix the error with one of the above solutions.

Also read: Alternative to Magento 2 Deprecated Load, Save and Delete Methods.

Thanks!

Table of Contents