Install ownCloud on Ubuntu 20.04 LTS DigitalOcean

ownCloud is an open source, self-hosted file sync and file share platform similar to Dropbox. If you’re looking for a self-hosted file share and sync platform, then ownCloud should be a good place to start.

This is a short guide to installing ownCloud on a fresh installation of Ubuntu 20.04 LTS on DigitalOcean.

This same process also applies to a stand alone PC with Ubuntu 20.04 installed.

Video Tutorial:

Update Your System

First, ensure that all the installed packages are up to date and that PHP is available in the APT repository.

apt update && \
apt upgrade -y

Create the occ Helper Script

Create a helper script to simplify running occ commands:

cat <<EOM >$FILE
#! /bin/bash
cd /var/www/owncloud
sudo -E -u www-data /usr/bin/php /var/www/owncloud/occ "\$@"

Make the helper script executable:

chmod +x $FILE

Install the Required Packages

apt install -y \
apache2 libapache2-mod-php \
mariadb-server openssl redis-server wget php-imagick \
php-common php-curl php-gd php-gmp php-bcmath php-imap \
php-intl php-json php-mbstring php-mysql php-ssh2 php-xml \
php-zip php-apcu php-redis php-ldap php-phpseclib

Install smbclient php Module

If you want to connect to external storage via SMB you need to install the smbclient php module.

First install the required packages:

apt-get install -y libsmbclient-dev php-dev php-pear

Then install smblclient php module using pecl:

pecl channel-update
mkdir -p /tmp/pear/cache
pecl install smbclient-stable
echo "" > /etc/php/7.4/mods-available/smbclient.ini
phpenmod smbclient
systemctl restart apache2

Check if it was successfully activated:

php -m | grep smbclient

This should show the following output:


Install the Recommended Packages

Additional useful tools helpful for debugging:

apt install -y \
unzip bzip2 rsync curl jq \
inetutils-ping ldap-utils \

Configure Apache

Create a Virtual Host Configuration

cat <<EOM >$FILE
<VirtualHost *:80>
# uncommment the line below if variable was set
#ServerName $my_domain
DirectoryIndex index.php index.html
DocumentRoot /var/www/owncloud
<Directory /var/www/owncloud>
Options +FollowSymlinks -Indexes
AllowOverride All
Require all granted

<IfModule mod_dav.c>
Dav off

SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud

Enable the Virtual Host Configuration

a2dissite 000-default
a2ensite owncloud.conf

Create OwnCloud Database

Now that you’ve install all the required packages, continue to start configuring the server.

Note: All words hightlight can be modified to your liking, the “ownclouduser and password” must be changed to something other that the default.

To connect to MariaDB server, run the commands below.

sudo mysql -u root -p

Then create a database called owncloud


Create a database user called ownclouduser with new password

CREATE USER 'ownclouduser'@'localhost' IDENTIFIED BY 'password_here';

Then grant the user full access to the database.

GRANT ALL ON owncloud.* TO 'ownclouduser'@'localhost' IDENTIFIED BY 'password_here' WITH GRANT OPTION;

Now, save your changes and exit.


Enable the Recommended Apache Modules

a2enmod dir env headers mime rewrite setenvif
systemctl restart apache2

Download ownCloud

cd /var/www/
wget && \
tar -xjf owncloud-complete-latest.tar.bz2 && \
chown -R www-data. owncloud

Install ownCloud

Remember to set a strong password for your owncloud admin user and provide the previously set password for the database user as the –database-pass argument.

occ maintenance:install \
--database "mysql" \
--database-name "owncloud" \
--database-user "owncloud" \
--database-pass "sec_db_pwd" \
--data-dir "/var/www/owncloud/data" \
--admin-user "admin" \
--admin-pass "sec_admin_pwd"

Configure ownCloud’s Trusted Domains

my_ip=$(hostname -I|cut -f1 -d ' ')
occ config:system:set trusted_domains 1 --value="$my_ip"
occ config:system:set trusted_domains 2 --value="$my_domain"

Configure the cron Jobs

Set your background job mode to cron:

occ background:cron

Configure the execution of the cron job to every 15 min and the cleanup of chunks every night at 2 am:

echo "*/15 * * * * /var/www/owncloud/occ system:cron" \
| sudo -u www-data -g crontab tee -a \
echo "0 2 * * * /var/www/owncloud/occ dav:cleanup-chunks" \
| sudo -u www-data -g crontab tee -a \

Configure Caching and File Locking

occ config:system:set \
memcache.local \
--value '\OC\Memcache\APCu'
occ config:system:set \
memcache.locking \
--value '\OC\Memcache\Redis'
occ config:system:set \
redis \
--value '{"host": "", "port": "6379"}' \
--type json

Configure Log Rotation

sudo cat <<EOM >$FILE
/var/www/owncloud/data/owncloud.log {
size 10M
rotate 12
compresscmd /bin/gzip

Make sure the permissions are correct

cd /var/www/
chown -R www-data. owncloud


I started this tech blog back in 2011 as a place to write down processes I took to fix my client systems and network. Now I write some tips and tricks to help others with the tech issues that one might encounter.

You may also like...