Skip to content

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

Closed
@rkapu

Description

@rkapu

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions