Magento 2 Customize base directory path

Magento 2 Customize base directory path

In this post we will give you Customize base directory path in Magento 2, hear for Magento 2 Customize base directory path we will give you details about it.

Introduction to Magento base directory paths

The MAGE_DIRS environment variable enables you to specify custom base directory paths and fragments of base URLs that are used by the Magento application to build absolute paths to various files or for generating URLs.

Set MAGE_DIRS

Specify an associative array where keys are constants from \Magento\App\Filesystem\DirectoryList and values are absolute paths of directories or their URL paths, respectively.

You can set MAGE_DIRS in any of the following ways:

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
     DirectoryList::PUB => [DirectoryList::URL_PATH => '',
     DirectoryList::MEDIA => [DirectoryList::PATH => '/mnt/nfs/media', DirectoryList::URL_PATH => ''],
     DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
     DirectoryList::UPLOAD => [DirectoryList::URL_PATH => '/mnt/nfs/media/upload'],
     DirectoryList::CACHE => [DirectoryList::PATH => '/mnt/nfs/cache'],
];
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

The preceding example sets paths for [cache] and [media] directories to /mnt/nfs/cache and /mnt/nfs/media, respectively.

Hope this code and post will helped you for implement Customize base directory path in Magento 2 . if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

59  +    =  66

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US