ANS Documentation

Improve This Doc
  • Cloud
  • Domains and DNS management
  • Backup and High Availability
  • eCommerce Stacks
    • Magento
      • Magento 1
      • Magento 2
    • Shopware
    • WooCommerce
    • AeroCommerce
  • Security
  • Email
  • Monitoring and usage management
  • Networking
  • Operating systems
  • Webcelerator
  • MyUKFast
  • Home >
  • eCommerce Stacks >
  • Magento >
  • Magento 2 >
  • NFS

NFS¶

Distributed Files/Folders¶

It’s very important to only use NFS for files/folder which need to be distributed between multiple servers. We strongly advise against having the entire document root of your Magento website on NFS. For Magento2, the typical directories that need NFS are:

  • pub/media

  • pub/static

There are a number of ways in which you can achieve this.

Customise MAGE_DIRS¶

You can set MAGE_DIRS in any of the following ways:

Bootstrap Parameters¶

Please refer to the Magento guide on how to set the value of bootstrap parameters: https://devdocs.magento.com/guides/v2.3/config-guide/bootstrap/magento-how-to-set.html

Custom Entry Point Script¶

You can use a custom entry point script such as the following:

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 => '/nfsshare/media', DirectoryList::URL_PATH => ''],
 	    DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
 	    DirectoryList::UPLOAD => [DirectoryList::URL_PATH => '/nfsshare/media/upload'],
 	    DirectoryList::CACHE => [DirectoryList::PATH => '/nfsshare/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);

Direct Mount Point¶

You can directly mount NFS to the folder within your document root:

NFSSERVER/nfsshare/media -> /var/www/vhosts/magentodomain.com/htdocs/pub/media

You can do this with the following entry in /etc/fstab:

 ~]# cat /etc/fstab | grep -i nfs
NFSSERVER:/nfsshare/media /var/www/vhosts/magentodomain.com/htdocs/pub/media nfs rw,noatime,nodiratime,async,timeo=1800 0 0
 ~]# mount /var/www/vhosts/magentodomain.com/htdocs/pub/media

Symlinks¶

You can symlink files/folders from your document root to the NFS mount point.

~]# ln -s /var/www/vhosts/magentodomain.com/htdocs/pub/media /nfsshare/media

Here’s some more information on the NFS service

Next Article > File/Directory Outside /pub

  • Useful Links
  • SMB
  • Enterprise
  • Channel
  • Public Sector
  • ANS Data Centres
  • About ANS
  • Careers
  • Blog
  • Get in touch
  •  
  • Sales 0800 458 4545
  • Support 0800 230 0032
  • Get in touch

© ANS Group Limited | Terms and Conditions | Corporate Guidance | Sitemap
ANS Group Limited, registered in England and Wales, company registration number 03176761, registered office 1 Archway, Birley Fields, Manchester M15 5QJ