magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

Merged CSS/JS files require pub/static/_cache writeable, contrary to documentation #13225

Open scottsb opened 6 years ago

scottsb commented 6 years ago

Preconditions

  1. Have Magento installed with two filesystem owners as documented, with all code files (source and CLI-generated) read-only for web server user. This includes the full pub/static directory.
  2. Turn on the merging of CSS or JS files.

Steps to reproduce

Clear static file cache and load home page.

Expected result

No exception should be generated.

Actual result

Exception is logged:

[2018-01-16 16:18:56] main.CRITICAL: Directory "/var/www/html/___/pub/static/_cache/merged" cannot be created Warning!mkdir(): Permission denied {"exception":"[object] (Magento\\Framework\\Exception\\FileSystemException(code: 0): Directory \"/var/www/html/___/pub/static/_cache/merged\" cannot be created Warning!mkdir(): Permission denied at /var/www/html/___/vendor/magento/framework/Filesystem/Driver/File.php:225)"} []

Commentary

This could arguably be seen as a documentation issue in which case I can report it in the devdocs repo. However, as I understand it, it seems that the documentation does describe the intended state, meaning the code should be changed instead. I'm not sure if it's possible, but if it were, ideally the merged files would be generated by static-content:deploy as alluded to in #9542. This would allow multiple servers in a cluster to be certain to have the merged files present in response to requests without the directory being shared among the nodes.

bsp-cory commented 2 years ago

@mattgrul if there is a PR, I would LOVE to see it. This has been driving me nuts for a couple of years now, and it would really help my quality of life if I didn't have to keep selectively changing permissions on these static files.

kanevbg commented 2 years ago

I do not see PR either. Would be very pleased to see such too. Same opinion as of @Stoyvo , it's really unacceptable and pretty strange such a flaw to exists so much time on such advanced system. Someone should add more labels, like "platform health"

erfanimani commented 2 years ago

For those wondering, the PR is likely created on Adobe's internal VCS, so you know it's being worked on.

engcom-Hotel commented 2 years ago

Hello @mattgrul @bsp-cory @kanevbg @erfanimani,

The label Progress: PR Created was added due to the wrong status made in JIRA. It was corrected. Currently, there is no PR created for this issue.

We have tried to reproduce the issue in the latest development of Magento ie 2.4-develop but the issue is not reproducible. It might the issue is fixed and merged with the development branch.

The steps we have followed are as follows:

  1. Followed the below documentation to create 2 users one is for the web server and the other one is for CLI: https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/deployment/file-system-permissions.html https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/prerequisites/file-system/configure-permissions.html?lang=en#about-the-shared-group
  2. Install Magento in the folder.
  3. Change with production mode: bin/magento deploy:mode:set production
  4. Ran static content deploy command: bin/magento setup:static-content:deploy
  5. Try to access the Homepage.

We are able to access the homepage without any issues. Please let us know in case we have missed anything.

Thanks

dooblem commented 2 years ago

Did you enable merge js/css as mentionned in the issue ?

mattgrul commented 2 years ago

@engcom-Hotel It seems like you are not fully understanding the issue. If you read through the entire thread you will see this is an issue with load-balanced environments. The contents of static/_cache should be written during the compile stage, not, during the first initial web request.

Stoyvo commented 2 years ago

@engcom-Hotel

The appropriate way to test this will be:

  1. Magento 2 is installed, functional, visible on frontend.
  2. Change to Production mode php bin/magento deploy:mode:set production
  3. Enable "merged css": php bin/magento config:set dev/css/merge_css_files 1
  4. Flush Cache just incase php bin/magento cache:flush
  5. On server, verify no merged css files exist in ls pub/static/_cache/merged/
  6. Run static content deploy: php bin/magento setup:static-content:deploy
  7. Verify merged css is visible: ls pub/static/_cache/merged/
  8. Load frontend by loading Magento 2 in web browser
  9. Check again for merged css ls pub/static/_cache/merged/

IF merged css is missing in Step 7 AND missing in Step 9, then merged CSS is not working correctly, please retry the steps.

IF merged CSS is missing in Step 7, but is visible in Step 9, then you have correctly recreated the issue. Static content deploy did not generate the file as it's expected to.

engcom-Hotel commented 2 years ago

Hello @Stoyvo,

Thanks for the detailed steps. We have followed the above steps as well. and for is the issue is still not reproducible. I have to add some points here to notice:

  1. We have used the shared group as mentioned in this document..
  2. We already have a www-data user in the www-data group, so we create one more user in the same group with CLI/SSH access.

Please let us know if we have missed anything.

Thanks

github-jira-sync-bot commented 2 years ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-1005

erfanimani commented 1 year ago

Related issue: https://github.com/magento/magento2/issues/29172

p24-max commented 1 year ago

I'm also facing this issue. pub/static/_cache/merged/ files are not generated with command bin/magento setup:static-content:deploy. The first request(s) are extremly slow due to this.

Only "workaround" what I currently found is disabling the CSS merging, but this is not a solution. Does someone found a better workaround to keep merging enabled?

-- bump @engcom-Hotel

Stoyvo commented 1 year ago

@p24-max

Does someone found a better workaround to keep merging enabled?

I use GCP containers with a "gfuse" mount to a public storage bucket where first request builds it, but it is used on every request going forward. This adds overhead to my container start time, but it's faster than rebuilding merged css.

gwharton commented 3 months ago

7 years on, and we're all still generating static content triggered by the first few browsers of our sites.