Store all Owncloud files on NFS external storage as primary in Ubuntu 16.04


This article will guide you through the process of moving your Owncloud storage from your local drive to a NFS share. This is preferable to local storage because the share can be removed and mounted to different hosts, separate to the Owncloud application. It also allows you to easily expand storage. This guide will work even if you have already started using Owncloud and have files stored with it.

First of all, you’ll want to expose your NFS share on the hosting server and mount it on your Owncloud server. That step isn’t covered here but https://help.ubuntu.com/community/SettingUpNFSHowTo is a good guide.

For this guide I’m assuming you’ve mounted the share at /mnt/owncloud_data/ and your Owncloud directory is /var/www/owncloud

The process is to copy the existing Owncloud data data to this mount, and then change some config to allow Owncloud to use this folder as the primary data store.

Start by copying everything from the existing data directory into your newly mounted directory (check hidden files have been copied too)

We need to allow PHP to allow file operations on the newly mounted directory, this can be done by  adding it to the open_basedir section in the php.ini file. Uncommenting this line means only the specified directory will be allowed for the purposes of file operations so we also have to add any other directories Owncloud will be using. Open up the php.ini file for apache. Mine was located at /etc/php/7.0/apache2/php.ini

uncomment/change the open_basedir directive to:

Next, we need to tell Owncloud to use the new data directory. Open the Owncloud config file (/var/www/owncloud/config/config.php) and change ‘data_directory’ from /var/www/owncloud/data to /mnt/owncloud_data

Finally, restart apache for the changes to take effect:

You should now be able to add files which will be stored on your nfs mount!

Leave a comment

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