Install ownCloud on Ubuntu 20.04


This is a short guide to installing ownCloud on a fresh installation of Ubuntu 20.04. Run the following commands in your terminal to complete the installation.

This guide can not go into details and has its limits by nature. If you experience issues like with dependencies of PHP or other relevant things like the operating system, web server or database, look at the Detailed Installation Guide for more information.


  • A fresh installation of Ubuntu 20.04 with SSH enabled.

  • This guide assumes that you are working as the root user.

  • Your ownCloud directory will be located in /var/www/owncloud/


First, ensure that all the installed packages are entirely up to date and that PHP is available in the APT repository. To do so, follow the instructions below:

apt update && \
  apt upgrade -y

Create the occ Helper Script

Create a helper script to simplify running occ commands.

/bin/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 /usr/local/bin/occ

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-imap php-intl \
  php-json php-mbstring php-mysql \
  php-ssh2 php-xml php-zip \
  php-apcu php-redis php-ldap

Note : php 7.4 is the default version installable with Ubuntu 20.04

apt install -y \
  ssh bzip2 rsync curl jq \
  inetutils-ping coreutils \


Configure Apache

Change the Document Root

sed -i "s#html#owncloud#" /etc/apache2/sites-available/000-default.conf
service apache2 restart

Create a Virtual Host Configuration

/bin/cat <<EOM >$FILE
Alias /owncloud "/var/www/owncloud/"

<Directory /var/www/owncloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off

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

Enable the Virtual Host Configuration

a2ensite owncloud.conf
service apache2 reload

Configure the Database

mysql -u root -e "CREATE DATABASE IF NOT EXISTS owncloud; \
  TO owncloud@localhost \
  IDENTIFIED BY 'password'";
echo "Enabling Apache Modules"
a2enmod dir env headers mime rewrite setenvif
service apache2 reload

Download ownCloud

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

Install ownCloud

occ maintenance:install \
    --database "mysql" \
    --database-name "owncloud" \
    --database-user "owncloud" \
    --database-pass "password" \
    --admin-user "admin" \
    --admin-pass "admin"

Configure ownCloud’s Trusted Domains

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

Set Up a Cron Job

Set your background job mode to cron

occ background:cron
echo "*/15  *  *  *  * /var/www/owncloud/occ system:cron" \
  > /var/spool/cron/crontabs/www-data
chown www-data.crontab /var/spool/cron/crontabs/www-data
chmod 0600 /var/spool/cron/crontabs/www-data

If you need to sync your users from an LDAP or Active Directory Server, add this additional Cron job. Every 15 minutes this cron job will sync LDAP users in ownCloud and disable the ones who are not available for ownCloud. Additionally, you get a log file in /var/log/ldap-sync/user-sync.log for debugging.

echo "*/15 * * * * /var/www/owncloud/occ user:sync 'OCA\User_LDAP\User_Proxy' -m disable -vvv >> /var/log/ldap-sync/user-sync.log 2>&1" >> /var/spool/cron/crontabs/www-data
chown www-data.crontab  /var/spool/cron/crontabs/www-data
chmod 0600  /var/spool/cron/crontabs/www-data
mkdir -p /var/log/ldap-sync
touch /var/log/ldap-sync/user-sync.log
chown www-data. /var/log/ldap-sync/user-sync.log

Configure Caching and File Locking

Execute these commands:

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

Execute this command to set up log rotation.

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

Finalise the Installation

Make sure the permissions are correct

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

ownCloud is now installed. You can confirm that it is ready to use by pointing your web browser to your ownCloud installation.

We recommend you check out the section Hardening and Security Guidance next.