diff --git a/app/code/Magento/Backend/etc/adminhtml/di.xml b/app/code/Magento/Backend/etc/adminhtml/di.xml
index fa327f645eb815b8a0381d023c5379b6cd26ee53..fcf2cc02e9fb972660c339a36674920458259610 100644
--- a/app/code/Magento/Backend/etc/adminhtml/di.xml
+++ b/app/code/Magento/Backend/etc/adminhtml/di.xml
@@ -138,4 +138,7 @@
             <argument name="isIncludesAvailable" xsi:type="boolean">false</argument>
         </arguments>
     </type>
+    <type name="Magento\Backend\Model\Menu\Builder">
+        <plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
+    </type>
 </config>
diff --git a/app/code/Magento/Backend/etc/di.xml b/app/code/Magento/Backend/etc/di.xml
index 9b282a65a479d1ebcc513ead8abf01b4de11c514..7307bbe09f1b4883ceb23ee78e8dfa41e9d74b13 100644
--- a/app/code/Magento/Backend/etc/di.xml
+++ b/app/code/Magento/Backend/etc/di.xml
@@ -214,7 +214,4 @@
             </argument>
         </arguments>
     </type>
-    <type name="Magento\Backend\Model\Menu\Builder">
-        <plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
-    </type>
 </config>
diff --git a/lib/internal/Magento/Framework/App/DocRootLocator.php b/lib/internal/Magento/Framework/App/DocRootLocator.php
index 39d40a6f1a00e3507c743e98ad2f77e08c99b4a9..23be6997202b06c11fd970a66cf7e311c9c43669 100644
--- a/lib/internal/Magento/Framework/App/DocRootLocator.php
+++ b/lib/internal/Magento/Framework/App/DocRootLocator.php
@@ -43,6 +43,6 @@ class DocRootLocator
     {
         $rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
         $readDirectory = $this->readFactory->create(DirectoryList::ROOT);
-        return strpos($rootBasePath, 'pub') && !$readDirectory->isExist($rootBasePath . 'setup');
+        return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
     }
 }