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

cp pub/static/.htaccess pub/.htaccess-sok-static

Rename the static folder

mv pub/static pub/static-`date +"%Y-%m-%d-%H-%M-%S"`

Deploy the static resources

php -d memory_limit=-1 bin/magento setup:static-content:deploy -f

If you have multiple languages, specify the languages separated by space

php -d memory_limit=-1 bin/magento setup:static-content:deploy -f en_US en_GB

Clear cache

php bin/magento cache:flush

Copy .htaccess file back to the “static” folder

cp pub/.htaccess-sok-static pub/static/.htaccess

Now static resources will work.

Back to Magento

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *