Before you begin using this guide, an ownCloud server needs to be installed and configured. You can set one up by following this guide. If our installation guide was used, then the
data directory is in ownCloud’s web root, which by default is located at
/var/www/owncloud. In this example, we are moving ownCloud’s
data directory to an attached additional storage volume that is mounted at
/mnt/owncloud. If you are using DigitalOcean, you can mount a block storage volume to fulfill that role by following our How To Use Block Storage on DigitalOcean guide. Regardless of the underlying storage being used, this guide can help you move the
data directory for ownCloud to a new location.
Step 1 – Moving the ownCloud Data Directory
When ownCloud is in use and backend changes are being made, there is the possibility that data may become corrupt or damaged. To prevent that from happening, we will stop Apache with the
sudo systemctl stop apache2
Some of the service management commands do not display an output. To verify that Apache is no longer running, use the
systemctl utility with the
sudo systemctl status apache2
The last line of the output should state that it’s stopped.
. . . Stopped LSB: Apache2 web server.
Warning: It is highly recommended that you backup your data prior to making any changes. Copy the contents of the
data directory to a new directory using the
rsync command. Using the
-aflag preserves the permissions and other directory properties, while the
-v flag provides verbose output so you can monitor the progress. In the example below, we back up our content into a new directory,
owncloud-data-bak, within our user’s home directory.
sudo rsync -av /var/www/owncloud/data/ ~/owncloud-data-bak/
With Apache stopped, we will move the
data directory to the new location using the
sudo mv /var/www/owncloud/data /mnt/owncloud/
data directory relocated, we will update ownCloud so that it’s aware of this change.
Step 2 – Pointing ownCloud to the New Data Location
ownCloud stores its configurations in a single file, which we will edit with the new path to the
datadirectory. Open the file with the
sudo nano /var/www/owncloud/config/config.php
datadirectory variable and update its value with the new location.
. . .
'datadirectory' => '/mnt/owncloud/data',
. . .
data directory moved and the configuration file updated, we are ready to confirm that our files are accessible from the new storage location.
Step 3 – Starting Apache
Now, we can start Apache using the
systemctl command and regain access to ownCloud:
- sudo systemctl start apache2
Finally, navigate to the ownCloud web interface:
ownCloud is a web application and does not have a way to verify the integrity of its configuration. Therefore, access to the web interface means the operation was successful.
In this tutorial, we expanded the amount of disk space available to ownCloud. We accomplished this by moving its
data directory to an additional storage volume. Although we were using a block storage device, the instructions here should be applicable for relocating the
data directory regardless of the technology being used.