[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?
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.
1 |
chmod -R 777 MAGENTO_2_ROOT_DIRECTORY/ |
Run the following command from Magento root for fixing the frontend:
1 |
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.
1 |
sudo gedit /etc/apache2/apache2.conf |
Replace the below code:
1 2 3 4 |
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride none Require all granted |
with:
1 2 3 4 |
<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:
1 |
bin\magento setup:static-content:deploy |
For Linux of ‘git bash’:
1 |
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:
1 2 3 |
<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:
1 |
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:
1 2 3 4 5 6 7 8 9 10 11 |
#/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.
If you need any help in implementing them, feel free to mention it in the Comments section below.
Thanks!
Related Post:
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
6 Comments
I tried this solution but still i get messy layout for both ( front and backend )
Hello,
Are you having issue in local or live server?
Is the file generated in pub/static for which you are getting the error?
I am using Xampp so need to change the apache2 settings ?
Hello,
No, you do not need to configure any changes in apache.
Thank you.
Thanks for sharing this great solution.
Well, is there a need to run the following command?
php bin/magento setup:upgarde
You need to run this command and the deploy command if the changes are not reflected after you implement the solution given in the post.