Skip to content

[2.x.x] Production mode is not detected in CLI => the uri for media and static are not good and contain pub #8868

@spipu

Description

@spipu

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

  1. Magento 2.
  2. Directory ./pub set as server document root.
  3. Created custom console command that returns base media url.

Steps to reproduce

  1. Open any image on your Magento site. make sure its url has no "pub" in path.
  2. Run console command that returns base media url.

Expected result

Command output does not contain "pub"

Actual result

Command output contains "pub"

Metadata

Metadata

Assignees

Labels

Event: distributed-cdDistributed Contribution DayIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions