Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento 2.4.2 old docroot logic does not work without workaround #32285

Closed
rkapu opened this issue Feb 25, 2021 · 19 comments
Closed

Magento 2.4.2 old docroot logic does not work without workaround #32285

rkapu opened this issue Feb 25, 2021 · 19 comments

Comments

@rkapu
Copy link

rkapu commented Feb 25, 2021

Hello!
On the other day i had a task to install magento 2.4.2 for testing purposes. I am holding my testing shops in subdirectories.
Version 2.4.2 does not work with that logic from the start because it's following new pub docroot path.
Magento is working perfectly fine if I will create a virtual host that points on pub directory. But on some testing servers i would preffer to hold different magento installations in subdirectories rather than creating a subdomains. So I tried to find the way for it to work with old logic and in my opinion I found some bugs that broke the old way of accesing magento which results into the need of implementing a workaround to work properly.

Preconditions

  1. Magento 2.4.2 Installation
  2. PHP 7.4
  3. Apache 2.4.18
  4. Elasticsearch 7.9.1

Steps to reproduce

  1. Install magento 2.4.2
  2. Make base url and apache virtual host point to magento installation in subdirectory (example 127.0.0.1/magento242/)
  3. Try to access 127.0.0.1/magento242. This immediately result into a 404 not found page. I looked at new .htaccess and found this line:
RewriteRule .* /pub/$0 [L]

Okay, that 404 error is expected because the request is redirected to 127.0.0.1/pub and I don't have it on my environment. I created that folder and index file for simple test and it worked as i expected.
4. Then I think that I just need to change that line to redirect into magento pub directory.

RewriteRule .* /magento242/pub/$0 [L]

That still gave me a 404 not found error but now it was a magento error page not the apache one because files from pub directory such as error page and static files were correctly downloaded on request. I tried going to admin url and it still does not work.
Okay I don't know why that do not work so I tried to change new array key in env.php config file directories=>document_root_is_pub to false. I cleared the cache but nothing changed.
5. In the next step I decided to implement the old way of accesing magento installation. I copied .htacces_sample into magento root installation as .htaccess, copied index.php from pub into the root folder of installation and changed require path to app/bootstrap.php in it. It is important to clear the cache on this step.
6. The home and admin page works perfectly now. They gave 200 response and not a 404 error page anymore. But there are issues with static files. They now give a 404 errors because of path changes in magento 2.4.2 that i think are relative to this commit 640cad5.
I tried to change value of directories=>document_root_is_pub because I think that this config value should regulate the correct paths but nothing changed. Either it is false or true the result is the same. I looked at the code and don't see any places where this config value would somehow be used. (I found only one place where it is set into $configData)
7. So I found 2 workarounds to this problem.

  • Make a redirect on top of .htaccess to pub if certain words are met in the REQUEST_URI.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond "%{REQUEST_URI}" "(/errors/|/static/|/media/|/opt/)"
  RewriteRule .* /magento242/pub/$0 [L]
</IfModule>
  • Make a symlinks from magento root to folders inside the pub directory such as errors, opt, static, media

Expected result

  1. I expected it to work and display all the pages but instead it displays 404 errors on any link such as homepage, admin_url but static files are downloaded fine.
  2. Expected it to work in this step too, because I haven't found a mention in 2.4.2 release notes that paths are changed to not include /pub/ anymore and now aren't compatible with old way of accessing magento.

Actual result

image

image

image

image

I didn't find how to add a label for Severity so I decide to leave it here. I think that is Severity: S1

@m2-assistant
Copy link

m2-assistant bot commented Feb 25, 2021

Hi @AstroniumGIT. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@incarnate
Copy link

I've had a similar experience as AstroniumGIT - fresh install in a subdirectory and changed the .htaccess file to include the subdirectory in the rewrite rule. Trying to access the setup resulted in infinite redirects to /pub/setup. After performing the installation via the CLI, all pages return 404 same as screenshot 4 above.

I can't find any documentation around this change (granted this is a tricky one to search for) or what needs to be done to ensure installation works in a subdirectory now.

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 5, 2021

cc @shiftedreality

@shiftedreality
Copy link
Member

shiftedreality commented Mar 5, 2021

Thank you for reporting this.

The change was done as part of the Remote Storage development track.

We have not found official mention of this installation flow in either public or internal documentation. Also, our manual tests showed it as partially broken in 2.4.1.
Is there any official documentation that mentions this as supported?

@khoimm92
Copy link
Contributor

khoimm92 commented Mar 5, 2021

This .htaccess rule works for me (remove the slash before pub/):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* pub/$0 [L]
DirectoryIndex index.php

@iphigenie
Copy link

I can't find any documentation around this change (granted this is a tricky one to search for) or what needs to be done to ensure installation works in a subdirectory now.

the new installation documentation simply puts "pub set as the document root" in the requirements, which simply washes its hands of all other scenarios.

@shiftedreality
Copy link
Member

shiftedreality commented Mar 9, 2021

You still can use index.php from the root folder.

We've adjusted root .htaccess to point to pub folder in a backward-compatible way.
Here is more on the change: #29176

So, in version 2.4.2+ you still have 3 options as before:

  1. Apache with the root .htaccess configured to point to pub: https://github.com/magento/magento2/blob/2.4.2/.htaccess
  2. Apache with the pub root
  3. Nginx with the pub root

Since having Magento in subdirectories is not officially supported and tested, I would encourage you to use a workaround and create a pull-request into DevDocs with the preferred method.

Otherwise, we do not have any tests or tools in place to verify this installation method.

@iphigenie
Copy link

iphigenie commented Mar 10, 2021

I understand that having magento in subdirectories is not supported since 2.2 or somewhere in 2.3 - it would have been nice if so many installation instructions and hosting companies didn't still make it a default.

but here's what the current installation instructions say in https://devdocs.magento.com/guides/v2.4/install-gde/composer.html - this will not produce a functioning site in 2.4.2

    This example assumes that the Magento install directory is named magento2ee, 
   the db-host is on the same machine (localhost), and that the db-name, db-user, and db-password are all magento:

   bin/magento setup:install \ --base-url=http://localhost/magento2ee \ --db-host=localhost \ --db-name=magento \ --db-user=magento \ --db-password=magento \ --admin-firstname=admin \ --admin-lastname=admin \ --admin-email=admin@admin.com \ --admin-user=admin \ --admin-password=admin123 \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1

I've wasted a few test installs so far trying to get a 2.4.2 instance - installed with the new desired root and route through pub setup - that works with a base url of http://mysite.com/shop

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 11, 2021

Maybe this link https://devdocs.magento.com/guides/v2.4/install-gde/tutorials/change-docroot-to-pub.html will have more clear about this

@shiftedreality
Copy link
Member

@iphigenie is this solved for you with alternative configuration instructions?

I will be happy to help with any documentation updates if needed.

@mrtuvn
Copy link
Contributor

mrtuvn commented Mar 11, 2021

CC: @dobooth may be we need add issue clarify this section in devdocs

@dobooth
Copy link
Contributor

dobooth commented Mar 17, 2021

Thanks for the great conversation here. I would be happy to help with any PR around this. Is this a matter of removing the magento2ee subfolder from the install url? And making a note that installing into subfolders is not allowed?

@shiftedreality
Copy link
Member

We've performed an investigation and found the solution with symlinks (https://magento.stackexchange.com/a/332419/38801) to be working fine on 2.4.2. We will proceed with official documentation for it.

Please let me know if there any other use cases that need investigation.

@shiftedreality
Copy link
Member

shiftedreality commented Apr 13, 2021

@hostep
Copy link
Contributor

hostep commented Apr 13, 2021

@shiftedreality: please link to publicly visible repositories, the link you put here is a private repository, thanks! 🙂

@shiftedreality
Copy link
Member

@hostep thanks for noticing this, changed to link on DevDocs instead of private PR

@mrtuvn
Copy link
Contributor

mrtuvn commented May 1, 2021

Hi @shiftedreality Is there any link available in devdocs for guide setup multiple domain/stores with 2.4.2 root pub changes

@rkapu
Copy link
Author

rkapu commented May 30, 2021

Thank you all for colaboration!
I`m glad that DevDocs were updated.

@rkapu rkapu closed this as completed May 30, 2021
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board May 30, 2021
@iphigenie
Copy link

@shiftedreality I got rid of the subfolders but I can't help but notice that the installation instructions https://devdocs.magento.com/guides/v2.4/install-gde/composer.html are STILL GIVING EXAMPLES THAT LEAD TO GENERAL 404

These need to be modified to something that works on 2.4.2

Because people are following these instructions and you can find them on stack exchange "fresh install doesnt work" https://magento.stackexchange.com/questions/337808/magento-2-fresh-install-showing-whoops-our-bad-404-page-not-found/339249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants