Magento 2 – Fixing Nginx pub/static Not Autogenerating Issue

command linemagento2static-content

I have tried many of the solutions from: Local installation of Magento 2 doest not generate files in the pub/static folder and similar posts:

I am in developer mode (verified in command line, and I can see error messages on the page for php). I am running Nginx with php-fpm from a 16.04 Ubuntu in vmware.

So far I've tried:

  1. chmod -R 777 on the var and pub folders

  2. chown -R www-data:www-data on the var and pub folders, I've also tried them as owned by root with 777 perms.

  3. tried the suggestion about changing from Symlink to Copy in app/etc/di.xml file

  4. pub/static.php and pub/static/.htaccess I can verify exist and are correct

So I go to the browser (and my browser has cache disabled in network tab) and load a frontend or admin page and none of the pub/static file stuff is generated, the page loads but with no css, js, etc.

If I delete the pub/static I can re-generate them with php bin/magento setup:static-content:deploy and that works fine, but the issue is that anytime I make a change to a template file or js file, I have to delete pub/static and run that command which is very slow and not practical for development. So my questions are:

  1. Any suggestions?

  2. Could this have to do with how I have the owner and group of the Magento files? I am not sure how that should be. It seems like php-fpm runs as www-data but I'm not 100% sure about that, I am not good with linux.

  3. Could it have to be with the user that I use when running php bin/magento setup:static-content:deploy? Which user should that be in command line? Usually I run it as root. But as I mentioned, I've manually changed the pub and var folders and files to www-data but it doesn't help.

  4. Or maybe it has to do with how I have the Mage Root set? I'm using the default nginx.conf file included, and have mage root set like: set $MAGE_ROOT /var/www/html/magento2; (my magento 2 files and folders are in that directory)

Best Answer

0) Verify, Are content of js/css files is cached in a browser?

1) Install xdebug and try to debug pub/static.php

2) I am using www-data groups and magento user and 777 for static files.

3) see 2). Do not use root to run static files deploy and do not run it in developer mode. Also, you need clean pub/static folder after setup:static-content:deploy running, because its break automatic redeploy.

4) It looks right

Related Topic