-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
This is a technical issue. It occurs on every edition (CE an EE) and every version (2.0.0 -> 2.1.5) of Magento.
When we are in Production Mode, and if we use the pub
folder as main public folder, then all the static url and media url must not contain the pub
part. That's normal.
It is not a automatic switch made on the magento mode value, but its depends on the index.php file that is used.
In the file ./pub/index.php
, it overrides the directoryList's config (given to the bootstrap) with the following :
$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'],
];
https://github.com/magento/magento2/blob/2.1/pub/index.php#L27
This configuration overriding is not present in the developer mode index.php :
https://github.com/magento/magento2/blob/2.1/index.php#L36
The pb is that when we are in production mode, if we ask for a static url or a media url in CLI, then the urls are not good and contain the pub part.
It is because, in CLi, there is no switch that will detect if we are in production or not, and if the directoryList configuration have to be overridden or not.
It could be in Magento\Framework\Console\Cli::getApplicationCommands
at line 127:
https://github.com/magento/magento2/blob/2.1/lib/internal/Magento/Framework/Console/Cli.php#L127
=> For now, it is impossible to send emails in CLI if we are in production mode, because the website logo will not work...
Preconditions
- Magento 2.
- Directory ./pub set as server document root.
- Created custom console command that returns base media url.
Steps to reproduce
- Open any image on your Magento site. make sure its url has no "pub" in path.
- Run console command that returns base media url.
Expected result
Command output does not contain "pub"
Actual result
Command output contains "pub"