2

Magento 2 ships with an index.php and .htaccess file in the pub folder

pub/index.php

This is good, as it allows Apache or nginx to be configured with a web root that's more secure.

However, Magento 2 also ships with an index.php file in the root project folder. Per previous comments from internal product owners, this is to work with web hosts that don't allow users to set a different web root.

Additionally, Magento 2 also ships with a few "mini-applications" that live off the root folder.

./setup/index.php
./update/index.php

One is the GUI installer (setup). The other is something called that component manager (update), an application that's presumed to be part of Magento 2 marketplace.

Is it possible to run Magento 2 using the more secure pub mode and still access these mini applications?

Or do you need to run Magento in the less secure "root index.php" mode to access them?

2

On Nginx (using the vhost sample configuration file included in the magento distribution) pointing the server root to pub folder I have access to setup/index.php by this url:

http://{magento_base_url}/setup

I guess the magic occurs here:

Nginx Vhost File

...
location /setup {
    root $MAGE_ROOT;
    location ~ ^/setup/index.php {
        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/setup/(?!pub/). {
        deny all;
    }

    location ~ ^/setup/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}
...

I haven't tried /update yet but there is a similar configuration in the nginx vhost file.

Full nginx vhots file here.

I guess that for apache users would be "nice to have" a vhost configuration sample like the nginx one, to avoid the .htaccess rewrites.

  • +1 Good to know -- do the applications behave correctly? i.e. Are file paths and URLs are generated correctly when running the application out of those folders? – Alan Storm Feb 15 '16 at 2:42
  • Mmh I can't confirm that, actually the install setup works perfect but i have several errors when I try to update (from 2.0.0 to 2.0.2) I can't pass the readyness check, that errors could be related to paths, but i didn't checked well yet. – MauroNigrele Feb 15 '16 at 3:12
1

shorter answer is: you define master root folder location:

and then you can manipulate with it, per server{}:

server { 
##################################
## Set Magento root folder
set $MAGE_ROOT /var/www/html;
##################################
## Set main public directory /pub
root $MAGE_ROOT/pub;
##################################

per location{}, etc:

location ~ ^/(setup|update) {
## Set main setup directory /
root $MAGE_ROOT;
##################################

about apps behavior: paths and locations translated to php-fpm, so it is important how your backed/php is configured.

for Apache 2.4+ server the same logic can be configured using mod_macro: https://httpd.apache.org/docs/2.4/mod/mod_macro.html

<Macro DocRoot ${docroot}>
    DocumentRoot "/var/www/${docroot}/htdocs"
</Macro>
  • That's good for nginx, but what about apache? – Alan Storm Feb 15 '16 at 16:49
  • Please see answer updated – MagenX Feb 15 '16 at 18:11
  • and have these mini-application been vetted to work with these configurations? Will paths, URLs, and asset URLs be correctly generated? – Alan Storm Feb 15 '16 at 18:30
  • you have to try :) but i guess as long as you have all correctly configured it will work – MagenX Feb 15 '16 at 19:33
  • Re: I have to try -- I'm not spending a few days doing free QA work for Magento Inc. :) – Alan Storm Feb 15 '16 at 19:39

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.