Installing and Configuring OwnCloud

Get started with installing and configuring OwnCloud 9. Share and store your files on your own cloud server.

Jérémie KassianoffCybernetics team 5 min read
Certified inLPI Linux Essentials – Exam 010-150
Installing and Configuring OwnCloud

Real-world use case

You want to host your own files rather than depend on a third-party cloud: here's how to install and configure OwnCloud 9.

OwnCloud

OwnCloud is a storage and file sharing service, available in two versions. In this article we'll use the community version. For this Cloud service to work, it needs:

  • A web server: Apache2 and php5.
  • A database server: MariaDB.

OwnCloud lets you keep control over your data, and everything can be linked to an LDAP server. Link sharing, inter-OwnCloud replication, and other features make OwnCloud one of the best alternatives* to giants like Google Drive, DropBox, or OneDrive, for example.
*There's also a fork of OwnCloud named NextCloud.

Installing the prerequisites:

We'll start by installing our packages, pair by pair:

bash
apt-get install apache2 mariadb-server libapache2-mod-php5
apt-get install php5-gd php5-json php5-mysql php5-curl
apt-get install php5-intl php5-mcrypt php5-imagick

MariaDB

When installing maria-server, we had to create a root password to authenticate.
We'll use it to connect to the database:

bash
mysql -u root -p

Let's create the OwnCloud database with the "owncloud" account and the password: "mypassword":

bash
CREATE DATABASE IF NOT EXISTS owncloud;
GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY 'mypassword';

Let's now exit MariaDB:

bash
quit

We've configured our MariaDB database for OwnCloud (other compatible database servers exist).

Apache2

The web server needs to be changed:

bash
nano /etc/apache2/sites-available/000-default.conf

We're going to change a line named DocumentRoot to:

bash
<VirtualHost *:80>
        DocumentRoot /var/www/owncloud
</VirtualHost>

The default path our web server will point to will be in the owncloud folder.

Installing OwnCloud

Installing OwnCloud is very simple and doesn't require any special knowledge.
Let's download OwnCloud as a .zip:

bash
wget https://download.owncloud.org/community/owncloud-9.1.4.zip

Unzip is a program to add to our Debian distribution:

bash
apt-get install unzip

Let's unzip OwnCloud:

bash
unzip owncloud-9.1.4.zip

We rename the directory:

bash
mv owncloud-9.1.4 owncloud

Then let's copy it to the /var/www/ location:

bash
cp -r owncloud /var/www/

We're going to give ownership of the owncloud directory to the www-data user and group:

bash
chown -R www-data:www-data owncloud

From now on, our OwnCloud installation is done, and we'll move on to the configuration.

Configuring OwnCloud

To configure our OwnCloud, let's head to the server's IP address (e.g.: http://your\_ip).
We're going to provide the information needed to configure OwnCloud:

At the bottom, we find the database credentials created earlier.
Once the fields are filled in, let's finish the installation and click finish setup to log in to OwnCloud:

Strengthening OwnCloud's security:

Right from the first login, let's head to the admin tab, at the top left of our username. Red lines appear, indicating certain issues:

  1. OwnCloud's data folder is, by default, in /var/www/owncloud/data, we need to move it.
  2. HTTPS access is strongly recommended to strengthen security and encrypt exchanges.
  3. We might also want to add caching for better performance.

We're going to resolve these red lines one by one:

  1. Let's move OwnCloud's data folder, for example to: /home/our_user/dataowncloud/:
    bash
    mv /var/www/owncloud/data/ /home/our_user/dataowncloud
    

    Let's not forget to restore read/write access permissions for the web server:
    bash
    chown -R www-data:www-data /home/our_user/dataowncloud
    

    Then let's change OwnCloud's configuration:
    bash
    nano /var/www/owncloud/config/config.php
    

    On the datadirectory line, change it like this:
    bash
    'datadirectory' => '/home/our_user/dataowncloud',
    
  2. For SSL support on the web server, let's enable the a2enmod headers mode:
    bash
    a2enmod headers
    

    Let's edit Apache2's ssl file:
    bash
    nano /etc/apache2/sites-available/default-ssl.conf
    

    Let's add between and this:
    bash
    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
    </IfModule>
    

    Let's also edit the non-ssl (default) file:
    bash
    nano /etc/apache2/sites-available/000-default.conf
    

    Let's add a redirect between and this:
    bash
    Redirect permanent / https://external_dns_name/
    

    Then let's edit the following file:
    bash
    nano /var/www/owncloud/config/config.php
    

    Let's add the following line to it:
    bash
    'forcessl' => true,
    
  3. To enable caching, let's install a specific PHP module:
    bash
    apt-get install php-apc
    

    Once again, let's change OwnCloud's configuration:
    bash
    nano /var/www/owncloud/config/config.php
    

    Let's add the following line:
    bash
    'memcache.local' => 'OCMemcacheAPC'
    

    Let's restart the Apache2 server:
    bash
    service apache2 restart
    

The result appears in admin as "All checks passed":

OwnCloud and LDAP connection

External accounts on an LDAP server can be connected to OwnCloud.
In the following example, I use Zimbra's LDAP server, which contains mail accounts.
To start, let's head to the second menu at the top left, under Apps:

Then, under the productivity tab, we find the addon: LDAP user and group backend 0.9.0
But for it to work, we'll need to install the php5-ldap package:

bash
 apt-get install php5-ldap

Adding the feature to the Apache2 server:

bash
a2enmod ldap

A restart of the web server is needed:

bash
/etc/init.d/apache2 restart

Let's select enable on our OwnCloud addon, then the configuration is fairly simple:

bash
  Server:         your server ip
  Port:           389
  Bind DN:        uid=zimbra,cn=admins,cn=zimbra
  Bind Password:  your_ldap_password
  Users DN:       ou=people,dc=kassianoff,dc=fr

The result should look similar to an established connection:

I invite you to read the article for more information on LDAP and hierarchy with Zimbra.
Now let's head to the Users tab of our OwnCloud server, where all our users are imported.
We've finished installing and configuring OwnCloud.

Conclusion

Jérémie Kassianoff

Cybernetics team

View profile

Read next

Migrating to PostgreSQL with Veeam Backup & Replication
Linux

Migrating to PostgreSQL with Veeam Backup & Replication

Read the article
Migrating VMware ESXi to Proxmox VE
Linux

Migrating VMware ESXi to Proxmox VE

Read the article
Deploying Microsoft Defender ATP with Ansible
Linux

Deploying Microsoft Defender ATP with Ansible

Read the article