For added security, we have configured DocumentRoot so that our Magento application is in the
pub/ Magento installation directory, as described in the official documentation.
However, there is now a problem when running commands on the command line – or when the own Magento cron is running: whenever a URL is generated for the front-end context, for example . via
$ this-> appEmulation-> startEnvironmentEmulation ( $ store-> getId (), Magento Framework App Area :: AREA_FRONTEND, true ) // ... $ this-> appEmulation-> stopEnvironmentEmulation ();
any generated front-end URL – like for product images, will always contain the
pub/ part of the URL.
pub / index.php replaces folder paths like this:
$ params = $ _SERVER; $ params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [ DirectoryList::PUB => [DirectoryList::URL_PATH => ''], DirectoryList :: MEDIA => [DirectoryList::URL_PATH => 'media'], DirectoryList :: STATIC_VIEW => [DirectoryList::URL_PATH => 'static'], DirectoryList :: UPLOAD => [DirectoryList::URL_PATH => 'media/upload'], ]; $ bootstrap = Magento Framework App Bootstrap :: create (BP, $ params); / ** @var Magento Framework App Http $ app * / $ app = $ bootstrap-> createApplication ( Magento Framework App Http :: class); $ bootstrap-> run ($ app);
that is, it just removes the
pub/ part of all these folder paths.
However, how do you do the same for the command line environment? (But only for the frontal context.)