Install ownCloud on Ubuntu 20.04

Install ownCloud on Ubuntu 20.04

Introduction

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.

Prerequisites

Preparation

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

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

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 

Install smbclient php module

apt-get install -y libsmbclient-dev php-dev php-pear
pecl install smbclient-stable
echo "extension=smbclient.so" > /etc/php/7.4/mods-available/smbclient.ini
phpenmod smbclient
systemctl restart apache2

Install the Recommended Packages

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

Installation

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

FILE="/etc/apache2/sites-available/owncloud.conf"
/bin/cat <<EOM >$FILE
Alias /owncloud "/var/www/owncloud/"

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

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/owncloud
 SetEnv HTTP_HOME /var/www/owncloud
</Directory>
EOM

Enable the Virtual Host Configuration

a2ensite owncloud.conf
service apache2 reload

Configure the Database

systemctl start mariadb
mysql -u root -e "CREATE DATABASE IF NOT EXISTS owncloud; \
GRANT ALL PRIVILEGES ON owncloud.* \
  TO owncloud@localhost \
  IDENTIFIED BY 'password'";

Enable the Recommended Apache Modules

echo "Enabling Apache Modules"
a2enmod dir env headers mime rewrite setenvif
service apache2 reload

Download ownCloud

cd /var/www/
wget https://download.owncloud.org/community/owncloud-complete-latest.tar.bz2 && \
tar -xjf owncloud-complete-latest.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" \
    --data-dir= "/var/www/owncloud"

Configure ownCloud’s Trusted Domains

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

Set Up a Cron Job

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
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": "127.0.0.1", "port": "6379"}' \
   --type json

Configure Log Rotation

FILE="/etc/logrotate.d/owncloud"
sudo /bin/cat <<EOM >$FILE
/var/www/owncloud/data/owncloud.log {
  size 10M
  rotate 12
  copytruncate
  missingok
  compress
  compresscmd /bin/gzip
}
EOM

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.

Hi, I’ve been having trouble with a new installation under Ubuntu 20.04. More on that later. But I wanted to say that while the help here is great, and while I thank you immensely for the work, there are a couple syntax errors that make it a tougher go than it needs to be.

I’m pretty sure both lines above should have an equals sign in place of the octothorpe ("#"), for instance.

On the above, “{webserver-user}.” seems to me to need to be replaced. I replaced it with www-data.; not sure if that’s right. But I am getting much closer to having things work now.

Just reporting, with perhaps some emphasis on my own dumbness about this: after hours of trying to figure out why this wasn’t working, I finally just pointed my browser at the raw IP address. And there is the server. But without https. I have no idea why the FQDN with cert under port 443 is not pointing to owncloud. What can I do?

Also, I can’t remember my admin password, but I see I will be able to reset it from occ. :slight_smile:

/dr

Hi,

thank you for your comment. The document had errors. I ported it over from a different format and had to replace all the = with #.

I fixed both issues you pointed out.

Regarding our question:

If you just followed this guide - you don’t have a domain name or certificates, you just have an ownCloud that is available under a ip address in http. What you would need is to get a domain name and then get certificates for it.

1 Like

You need to configure apache, with sites-enabled. Look for the first lines in the default and default ssl conf. where is document root?

1 Like

The server is a racknerd VPS of KVM virtualization type. There is one filesystem. I installed apache2 in the default manner with no special options. Document root is /var/www/html. The conf files appear to me to be in /etc/apache2/sites-enabled. In any case, I never deviated from defaults. My server’s hostname and a call to the letsencrypt cert appear in the conf files and don’t look erroneous to me, although I have no deep experience here.

Edited: Wait. You’re right! I just changed the default-le-ssl.conf file. The commented line was in there.

/etc/apache2/sites-enabled$ grep -R DocumentRoot *
000-default.conf:       DocumentRoot /var/www/owncloud
000-default-le-ssl.conf:        #DocumentRoot /var/www/html
000-default-le-ssl.conf:        DocumentRoot /var/www/owncloud

Amazing. You pretty much solved it! Thank you!

Now I am getting this message, though:

Okay, I solved that last issue myself by following directions. :wink: It’s all good! Much obliged, @dmitry.

2 Likes