How to install ownCloud on Debian 11

ownCloud is an open-source file sharing server and collaboration platform that can store your personal content, like documents and pictures, in a centralized location. This allows you to take control of your content and security by not relying on third-party content hosting services like Dropbox.

In this article, we will install and configure an ownCloud instance on a Debian server. We will also secure it with an SSL certificate and enable some useful features.

Prerequisites

In order to follow this article, you will need the following:

  • A Debian server with a sudo user and a firewall.
  • A LAMP stack (Linux, Apache, MySQL/MariaDB, and PHP). ownCloud requires a web server, a database, and PHP to function properly. You can install and configure this software by following the Debian LAMP stack guide.
  • An SSL certificate. How you set this up depends on whether or not you have a domain name that resolves to your server.
    • If you have a domain name, the easiest way to secure your site is with Let’s Encrypt, which provides free, trusted certificates. You can follow the Let’s Encrypt guide for Apache to set this up.
    • If you do not have a domain name, and you are just using this configuration for testing or personal use, you can use a self-signed certificate instead. This provides the same type of encryption, but without the domain validation. You can follow the self-signed SSL guide for Apache to get set up.

Step 1 – Installing ownCloud

The ownCloud server package does not exist within the default repositories for Debian. However, ownCloud maintains a dedicated repository for the distribution that we can add to our server.

To begin, let’s install a few components to help us add the ownCloud repositories. The apt-transport-https package allows us to use the deb https:// in our apt sources list to indicate external repositories served over HTTPS:

sudo apt update
sudo apt install curl apt-transport-https

Next, download the ownCloud release key using the curl command and import it with the apt-key utility with the add command:

curl https://download.owncloud.org/download/repositories/production/Debian_10/Release.key | sudo apt-key add -

The Release.key file contains a PGP (Pretty Good Privacy) public key which apt will use to verify that the ownCloud package is authentic.

In addition to importing the key, create a file called owncloud.list in the sources.list.d directory for apt. The file will contain the address to the ownCloud repository.

echo 'deb http://download.owncloud.org/download/repositories/production/Debian_10/ /' | sudo tee /etc/apt/sources.list.d/owncloud.list

Now, we can use the package manager to find and install ownCloud:

sudo apt update
sudo apt install owncloud-files

This will install the ownCloud files under /var/www/owncloud. We will configure Apache to serve this directory in the next step.

Step 2 – Configuring Apache for ownCloud

In this step, we will create an Apache configuration file for ownCloud and enable some required modules.

First, create a new file called owncloud.conf in the /etc/apache2/sites-available directory:

sudo nano /etc/apache2/sites-available/owncloud.conf

Paste the following configuration into the file. Replace example.com with your own domain name or IP address. If you are using Let’s Encrypt, make sure to use the full path to your certificate and key files under /etc/letsencrypt/live. If you are using a self-signed certificate, use the default paths under /etc/ssl.

<VirtualHost *:80>
    ServerName example.com

    # Redirect all HTTP requests to HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com

    # Enable SSL
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

    # Set the document root to the ownCloud directory
    DocumentRoot /var/www/owncloud/

    # Set the directory options and allow .htaccess files
    <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>

</VirtualHost>

Save and close the file when you are finished.

Next, enable the new site and some required Apache modules with the following commands:

sudo a2ensite owncloud.conf
sudo a2enmod rewrite headers env dir mime ssl

Finally, restart Apache to apply the changes:

sudo systemctl restart apache2

Step 3 – Finalizing the ownCloud Installation

In this step, we will complete the ownCloud installation using its graphical user interface.

Open your web browser and navigate to your ownCloud domain name or IP address. You should see a page like this:

Enter a username and password for the admin account. Then, click on the Storage & database dropdown menu. You should see a page like this:

Here, you can configure the data folder and the database for ownCloud. By default, the data folder is /var/www/owncloud/data, but you can change it to another location if you prefer. For the database, select MySQL/MariaDB and enter the database name, user, and password that you created in the LAMP stack guide. Then, click Finish setup.

You should see a page like this:

This means that you have successfully installed and configured ownCloud on your Debian server. You can now start using it to upload, sync, and share your files.

Step 4 – Securing ownCloud (Optional)

In this step, we will enable some optional security features for ownCloud.

First, we will enable HTTPS redirection for all requests. This will ensure that your connection to ownCloud is always encrypted. To do this, edit the config.php file in the /var/www/owncloud/config directory:

sudo nano /var/www/owncloud/config/config.php

Add the following line at the end of the file, before the closing );:

  'overwriteprotocol' => 'https',

Save and close the file when you are done.

Next, we will enable HTTP Strict Transport Security (HSTS) for ownCloud. This will instruct browsers to only connect to your site using HTTPS. To do this, edit the .htaccess file in the /var/www/owncloud directory:

sudo nano /var/www/owncloud/.htaccess

Find the following lines:

  # Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
  # Header always set Content-Security-Policy "upgrade-insecure-requests;"

Uncomment them by removing the # at the beginning of each line. Then, save and close the file.

Finally, we will enable two-factor authentication (2FA) for ownCloud. This will add an extra layer of security to your login process by requiring a verification code from your mobile device. To do this, log in to your ownCloud web interface as an admin user and click on your username at the top-right corner. Then, select Market from the dropdown menu.

Search for Two-Factor TOTP Provider and click on it. You should see a page like this:

Click on Install to install the app. Then, go back to your username and select Settings from the dropdown menu.

Click on Security in the left sidebar. You should see a page like this:

Click on Activate TOTP to enable two-factor authentication. You will be asked to scan a QR code with your mobile device using an app like Google Authenticator or Authy. After scanning the code, enter the verification code that appears on your app and click Verify.

You should see a message saying that two-factor authentication is enabled. You can also generate backup codes in case you lose access to your device. Make sure to save these codes somewhere safe.

Now, whenever you log in to ownCloud, you will be asked to enter a verification code from your app after entering your username and password. This will make your account more secure.

Conclusion

You have successfully installed and configured ownCloud on your Debian server. You have also secured it with an SSL certificate, HTTPS redirection, HSTS, and two-factor authentication. You can now use ownCloud to store, sync, and share your files with others.

Please keep in mind that ownCloud for personal use is free via community edition, so no need to pay anything to have your personal cloud solution to back up your computer, mobile, tablet or setup an automated website backup.

I hope you enjoyed this article and found it useful. If you have any questions or feedback, please let me know in the comments below. Thank you for reading! 😊