8

I removed the folder pub/static while in developer mode, expecting that things will generate back to the way they were. After that though, only the folder

_requirejs

got generated, so now I am missing everything - all css and js files are gone. How can I fix that problem ? Please, help.

  • Is the pub/static directory writable by the webserver? – Peter O'Callaghan Feb 17 '16 at 17:37
  • yes, it is writable by the webserver and the magento user. i gave ti 777 permissions just in case, to be abbsolutely sure – Lachezar Raychev Feb 17 '16 at 17:38
  • drwxrwsrwx 3 ubuntu www-data 4096 Feb 17 17:24 static the app/design/adminhtml/Magento and app/design/frontend/Magento directories are empy, i don't know if that is relevant – Lachezar Raychev Feb 17 '16 at 17:38
  • i can't switch back to default mode as well – Lachezar Raychev Feb 17 '16 at 17:40
  • 2
    why did they make it to not be possible to switch it back to default view? maybe you changed your mind and you don't want production mode to deploy your app – Claudiu Creanga Mar 16 '16 at 14:25
23

You can regenerate your static content by running the following command

php bin/magento setup:static-content:deploy

This is the command you'd run before deploying to production mode. If you're running in default or developer mode, those files should be generating for your automatically. My guess is you accidentally removed a folder Magento expects to be there -- running setup:static-content:deploy may restore that folder, or may result in an explicit error about the missing folders. If it's the later, the error should (hopefully!) provide enough information to rebuild the missing directories. You may want to run the command in verbose mode

php bin/magento -vvv setup:static-content:deploy

This will tell the bin/magento command to output the actual exception if there's an error.

  • yep, already found that. good that it has a marked answer now. thank you. and didn't know about the -vvv thing. this could be helpful. thank you one more time – Lachezar Raychev Feb 17 '16 at 19:16
  • 1
    Ironic... I encountered this problem with Magento 2.1.2, following the steps to install Commerce Bug 3 . From Alan Storm. This answer solved the problem though. – gwideman Nov 21 '16 at 2:42
  • @gwideman If you have a moment would you mind letting us know the problems you ran into when installing Commerce Bug 3? We're interesting in improving the experience as much as we can within the limitations setup by Magento Inc. pulsestorm.net/blog – Alan Storm Nov 21 '16 at 20:00
  • 1
    @AlanStorm Problem likely due to the site (which is a test site) being in production mode. In brief, following Commerce Bug's README, at magento setup:upgrade step, result message was "Please rerun Magento compile command". I ran magento setup:di:compile. After that the site didn't work -- no images or other static files like js. Basically, pub/static/frontend and pub/static/adminhtml were missing. Hence the need to run setup:static-content:deploy. – gwideman Nov 22 '16 at 23:43
  • If you are in development add -f to force and get the error – open-ecommerce.org Nov 3 '17 at 12:10
4

What caused this is that when you removed the pub/static folder itself, you removed an .htaccess file that is necessary for regenerating content while in production mode. Without that file, no assets will be automatically regenerated.

If this ever happens again, you could copy that file from another Magento 2 instance (if you have another one setup) or try to restore the file by copying the .htaccess from Magento's GitHub: https://github.com/magento/magento2/blob/develop/pub/static/.htaccess

To prevent this from happening, only empty the contents of a folder under the pub/static directory, such as frontend or adminhtml.

3

You just need to run this command to generate static content:

php bin/magento setup:static-content:deploy

Make sure the owner of pub static is same as your Magento owner.

Make sure you have the required .htaccess file in your folder.

2
  1. Remove all folders under pub/static
  2. Remove var/cache
  3. Remove var/composer_home
  4. Remove var/generation
  5. Remove var/page_cache
  6. Remove var/view_preprocessed

After this, go to the root of magento 2 and run:

php bin/magento setup:static-content:deploy

1

You can follow the below steps:-

1. Delete all folders under pub/static
2. Delete var/cache
3. Delete var/composer_home
4. Delete var/generation
5. Delete var/page_cache
6. Delete var/view_preprocessed

Now open your command prompt and go to your root installation of magento 2 and run the following commands

php bin/magento setup:static-content:deploy

0

If you removed the .htaccess file you could have lots of problems. (getting 404 errors when trying to access your css + javascript files and whatnot.

If this is happening to you the best way I found of fixing this is re-downloading the magento zip or tar and extracting the pub/static folder to your project directory. This should include the .htaccess file and fix any problem you have.

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.