1

I'm install a new project with magento 2 (M2), and use sample data of M2. This installation is success on my laptop, and M2 works fine.

After that, I compress source code of my project, then copy to another PC. This PC is installed the same environment with my laptop - (XAMPP), even using the same port

But, it does not work on the PC. I try to clean caching but many javascript/ css/ image files still cannot load.

When, i run this command: php bin\magento setup:static-content:deploy it works normally.

I really want to know what's happen in this case to get more knowledge about M2?

Please explain for me! Thank you!

  • have you run setup command? php bin/magento setup:upgrade – Rakesh Jesadiya Oct 10 '16 at 5:42
  • Yes, now it is working. But I want to know why? Could you explain for me? – namdt55555 Oct 10 '16 at 5:50
  • please let me know if you have any query – Rakesh Jesadiya Oct 10 '16 at 6:26
0

Whenever you made setup for magento 2 at that time, you have to run setup command and deployment command to run smoothly site.

using setup:upgrade command, your magento system all module are enable and display in admin and front panel or you have add any additional module those are active using this run command and you can check its active module under app/etc/config.php file.

ex. Module with Magento_Catalog => 1 means value 1 all those are active at time in system and value 0 with module are disable for now.

Whenever you have display console error for js,css means you have to run deployment command.

php bin/magento setup:static-content:deploy

Whenever you run this command at time all static view files are generated under pub/static folder of magento 2 system. when ever you install any magento 2 software you need to run this command for prevent js and css error.

Using This command all static view files are generated inside pub/static folder and all those files are manually cached in developer mode.

you can get more info from devdocs site, Deployment command information

  • Thank @Rakesh, I want to know how Magento2 works in this case. Because, I have already run these commands on my Laptop. And it works fine. I also saw js/css/image files that generated in "pub" folder. But when I copy to my PC, it does not work. And I have to run those commands again. So, it makes me don't understand. – namdt55555 Oct 10 '16 at 7:16
  • when you run this command all required static files js /css and html file are generated if not generate already inside pub static folder. so this command is need. – Rakesh Jesadiya Oct 10 '16 at 12:03
0

Perhaps my question is not clear. After checked again on my laptop. I've found & understand the reason.

Because My Laptop is MAC (unix), so when I run command to generate js/css/image on magento project, it will create some symlinks as example below:

cd pub/static/frontend/Magento/luma/en_US
ls -la 
jquery.js -> /Volumes/data/projects/magento/project1/lib/web/jquery.js

So, on my MAC, it works fine. But when I zip source code on my MAC, then copy to my PC (using Window 10 OS) Those symlinks cannot work. That is the reason that the project did not load some js/css files on my PC.

In order to run this project on my PC, I have to run this command again:

php bin/magento setup:static-content:deploy

This time, it will generate js/css/images again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.