Magento 2 css and js not loading while transfered to new server

Magento 2 css and js not loading while transfered to new server

August 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 css and js not loading while transfered to new server

Troubleshooting CSS & JavaScript Issues After Migrating Magento 2

As an experienced developer, I frequently encounter cases where Magento 2 fails to load CSS and JavaScript files after migration to a new server. This common issue can be quite frustrating, but with the right troubleshooting steps, it’s often straightforward to resolve.

Step 1: Verify File Permissions and Ownership

While you mentioned checking file permissions, it’s worth re-iterating this critical step. Ensure that your Magento files have the correct ownership and permissions for your server environment.

The pub/static directory should be owned by the web server user (e.g., www-data or apache) with read and write permissions:

chown -R www-data:www-data pub/static
chmod -R 2775 pub/static

The var/generation folder also needs to be writable:

chown -R www-data:www-data var/generation
chmod -R 2775 var/generation

Step 2: Static Content Deployment

You mentioned you’ve already performed a static deploy. If the issue persists, let’s explore some additional steps to ensure the deployment was successful.

First, delete the contents of pub/static and var/view_preprocessed:

rm -rf pub/static/*
rm -rf var/view_preprocessed/*

Next, run the following commands:

bin/magento setup:static-content:deploy
bin/magento cache:flush

Note that in some cases, you may need to set the STATIC_FILES_URL and MEDIA_FILES_URL configuration values manually if they don’t match the new server’s URL:

bin/magento config:set STATIC_FILES_URL "https://www.yournewdomain.com/pub/static/"

Step 3: Check Environment Variables

Ensure that your environment variables are configured correctly in app/bootstrap.php. The MAGE_MODE variable should be set to the appropriate value for your new server:

if (!defined('MAGE_MODE')) {
    define('MAGE_MODE', 'default'); // Change this to 'developer' if needed
}

Step 4: Clear Cache and Reindex

To ensure that Magento can properly load resources, it’s crucial to clear the cache and reindex your data:

bin/magento cache:flush
bin/magento indexer:reindex

Step 5: Review Error Logs

If you’ve followed all the steps above and are still experiencing issues, it’s time to review your error logs. The Magento error log is typically located at var/log/debug.log.

Look for any JavaScript or CSS-related errors that might indicate a missing file or configuration issue.

Conclusion: Resolving Magento 2 CSS & JS Loading Issues

In most cases, following the troubleshooting steps outlined above should help you resolve your Magento 2 CSS and JavaScript loading issues after migration. Remember to always keep your Magento installation up-to-date for optimal performance and security.

For more in-depth guides on Magento migrations and best practices, visit our official documentation at https://laravelcompany.com/magento-migration-guide/.

If the issue persists even after following these steps, please feel free to reach out to us. Our team of expert developers is always ready to assist you with any Magento-related challenges.

Magento 2 Cache Database Security

Our network