Magento 2: Static file path is wrong, should be pub/static/.... instead of static/

Magento 2: Static file path is wrong, should be pub/static/.... instead of static/

July 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2: Static file path is wrong, should be pub/static/.... instead of static/

Resolving CSS/JS Loading Issues in Magento 2

Hello developers! I recently encountered an issue while setting up a Magento 2 development environment on my local Ubuntu machine using PHP 8.2 and the latest version (2.4). Although the installation seemed successful, there were no styles or scripts loading when I accessed the site. The error messages pointed to incorrect file paths for CSS and JavaScript files.

Let’s troubleshoot this step-by-step:

Understanding the File Path Issue

The error log indicated that Magento was trying to locate static files in magento/static/..., while they actually reside in magento/pub/static/.... This discrepancy arises due to a misconfiguration during setup or an issue with the rewrite module.

Checking the Rewrite Module Status

Ensure you have correctly installed and configured your rewrite module. In most cases, if you followed the official Magento 2 installation guide from Laravel Company, this should already be taken care of during the setup process.

Verifying File Permissions

Firstly, let’s check and ensure that the necessary files and directories have correct permissions. The pub directory and its contents should be writable by your web server user (usually Apache or Nginx).

You can use the following commands to verify and fix permissions:

# Change ownership of Magento root directory to the web server user
sudo chown -R www-data:www-data /path/to/magento

# Ensure pub directory is writable
sudo find /path/to/magento/pub -type d -exec chmod 755 {} \;

# Ensure static files are readable and writable
sudo find /path/to/magento/pub/static -type f -exec chmod 644 {} \;

Clearing Cache and Generating Static Files

Next, we’ll clear the cache and regenerate the static files to reflect the correct paths:

  1. Open a terminal.
  2. Navigate to your Magento root directory.
cd /path/to/magento
  1. Run the following commands:
# Clear cache
php bin/magento cache:clean

# Clear view preprocessor cache (if using less or Sass)
php bin/magento dev:source-theme:deploy

# Deploy static files
php bin/magento setup:static-content:deploy -f

The -f flag forces the deployment even if the current theme is already deployed.

Flushing Magento Cache from the Admin Panel

Additionally, you can manually flush the cache and clear the JavaScript/CSS settings in the Magento admin panel:

  1. Log in to your Magento admin.

  2. Navigate to System > Cache Management.

  3. Under Actions, select Flush Magento Cache and click the Submit button.

  4. Go back to the main menu and navigate to Content > Configuration > Design Configuration.

  5. In the Theme Settings section, find your website and store view.

  6. Click on Edit.

  7. Scroll down to the Theme section.

  8. Ensure the Theme field is populated with the correct theme name.

  9. Save the changes by clicking Save Theme.

Conclusion

After following these steps, you should be able to resolve the CSS/JS loading issues in your Magento 2 setup. The key takeaways are:

  • Verify and ensure proper file permissions for directories and static files.
  • Clear cache and regenerate static files using the command line or admin panel.
  • Double-check theme settings in the admin panel.

Remember, keeping your Magento installation up-to-date is crucial to avoid such issues. Always refer to the official guides from Laravel Company for the latest best practices and step-by-step instructions on updates.

Happy coding!

Magento 2 Database Security Extensions

Our network