Magento 2 static resources missing after server change
After Migrating a Magento 2 site to a new server with a different folder structure (document root), static resources like CSS and JS files on the site stopped working. This error is because Magento uses symlinks, when you move the website to a new server with a different folder structure, these symlinks stop working.
To fix this, we need to regenerate static files.
First, make a copy of .htaccess file inside the static folder
1 |
cp pub/static/.htaccess pub/.htaccess-sok-static |
Rename the static folder
1 |
mv pub/static pub/static-`date +"%Y-%m-%d-%H-%M-%S"` |
Deploy the static resources
1 |
php -d memory_limit=-1 bin/magento setup:static-content:deploy -f |
If you have multiple languages, specify the languages separated by space
1 |
php -d memory_limit=-1 bin/magento setup:static-content:deploy -f en_US en_GB |
Clear cache
1 |
php bin/magento cache:flush |
Copy .htaccess file back to the “static” folder
1 |
cp pub/.htaccess-sok-static pub/static/.htaccess |
Now static resources will work.
Back to Magento