Introduction

OwnCloud is open-source software that enables you to create your own file sharing server, similar to Dropbox. Using OwnCloud you can easily view and sync calendar events, tasks, address books, and bookmarks. You can access OwnCloud using a nice looking web interface or install the OwnCloud client on a desktop machine. OwnCloud supports implementing user and group access restrictions on files.

In this tutorial, we will install and configure an OwnCloud server on using Ubuntu 16.04.

Requirements

Install LAMP Server

Before installing OwnCloud, you will need to update the OS and install the LAMP stack on your system.

You can do this by just running the following command:

sudo apt-get update && sudo apt-get upgrade -y
     sudo apt install -y apache2 mariadb-server libapache2-mod-php7.0 \
    php7.0-gd php7.0-json php7.0-mysql php7.0-curl \
    php7.0-intl php7.0-mcrypt php-imagick \
    php7.0-zip php7.0-xml php7.0-mbstring -y

Once installation is complete, start the Apache and Mysql services and enable them to start on boot:

sudo systemctl start apache2
sudo systemctl start mysql
sudo systemctl enable apache2
sudo systemctl enable mysql

You will also need to enable the rewrite module in Apache.

sudo a2enmod rewrite
sudo systemctl restart apache2

You will also need to secure Mysql, because the default configuration is not secure for production environments.

You can do this by running the following script:

sudo mysql_secure_installation

After running the above script, you will need to change the root password, disable and remove anonymous users from MySQL server, turn off the MySQL root user login remotely, delete the test database, and reload privilege tables on the system. Once you are finished your Mysql installation should be secure.

Install OwnCloud

By default an OwnCloud package does not exist in Ubuntu's standard repositories. So, you need to download their release key and import it with the apt-key command:

curl https://download.owncloud.org/download/repositories/stable/Ubuntu_16.04/Release.key | sudo apt-key add -

Next, create a repository address in the source directory for apt:

sudo nano /etc/apt/sources.list.d/owncloud.list

Add the following line:

deb http://download.owncloud.org/download/repositories/stable/Ubuntu_16.04/ /

Save the file and update the repository:

sudo apt-get update -y

Finally, install OwnCloud using the following command:

sudo apt-get install owncloud-files

Once installation is complete, you will need to restart the Apache server to apply the changes:

sudo systemctl restart apache2

Configure Database

You will also need to create a mysql database and user account for configuring OwnCloud.

Run the following set of commands to login to mysql server and create a database and user.

mysql -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE owncloud;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON owncloud.* to 'owncloud'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Mysql> flush privileges;
Mysql>exit

Create SSL Certificate to Secure OwnCloud

Next, you will need to create SSL certificate to secure your OwnCloud server.

Run the following command to create the SSL certificate :

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/owncloud.key -out /etc/ssl/certs/owncloud.crt

You should see the following output:

Generating a 2048 bit RSA private key
..........................+++
..................................................................+++
writing new private key to '/etc/ssl/private/owncloud.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:GUJARAT
Locality Name (eg, city) []:JUNAGADH
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ProfitBricks
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:HITESH
Email Address []:[email protected]

Once the SSL certificate is generated, create an Apache SSL virtual host entry for OwnCloud.

You can do this by creating the owncloud-ssl.conf file:

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

Delete all the lines and add the following content:

<VirtualHost *:80>

       ServerName www.mypics.realety.net

        ServerAdmin [email protected]

 

        # Redirect Requests to SSL

        Redirect permanent / https://www.mypics.realety.net

 

        ErrorLog ${APACHE_LOG_DIR}/error.log

        CustomLog ${APACHE_LOG_DIR}/error.log combined

 

</VirtualHost>

 

<IfModule mod_ssl.c>

    <VirtualHost _default_:443>

            ServerAdmin [email protected]

            ServerName 192.168.***

            DocumentRoot /var/www/owncloud

            ErrorLog ${APACHE_LOG_DIR}/error.log

            CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine on

            SSLCertificateFile /etc/ssl/certs/owncloud.crt

            SSLCertificateKeyFile /etc/ssl/private/owncloud.key

<IfModule mod_headers.c>

Header always set Strict-Transport-Security "max-age=15768000; preload"

</IfModule>

            <FilesMatch "\.(cgi|shtml|phtml|php)$">

                             SSLOptions +StdEnvVars

            </FilesMatch>

            <Directory /usr/lib/cgi-bin>

                            SSLOptions +StdEnvVars

            </Directory>

            BrowserMatch "MSIE [2-6]" \

                           nokeepalive ssl-unclean-shutdown \

                           downgrade-1.0 force-response-1.0

    </VirtualHost>

</IfModule>

 

Save the file and paste the following lines

 

Activate ssl site.

sudo a2enmod ssl
sudo a2ensite owncloud-ssl.conf

Disable old site

sudo a2dissite 000-default.conf

sudo a2dissite default-ssl.conf

Restart apache

sudo service apache2 restart

Move Data Files
sudo mv /var/www/owncloud/data /var/www

Change location in config file
sudo nano /www/owncloud/config/config.php
to 'datadirectory' => '/var/www/data',
also add this to file as well
'files_external_allow_create_new_local' => 'true',

chown -hR www-data:www-data /var/www/owncloud
chown -hR www-data:www-data /var/www/data

sudo chmod 777 -R /home/larry
sudo -u www-data php occ files:scan --all

If Needed
find / -name "owncloud" -type d

Uploaded pics
sudo chmod 777 -R /var/www/owncloud/data/Larry/files/Uploads

Configure OwnCloud

Once everything is up-to-date, it's time to access the OwnCloud web interface.

Open your favorite web browser and type the URL https://your-server-ip/owncloud, you should see the following page:

OwnCloud Login Page

Next, enter a username and password to create an administrator account for OwnCloud, click on the Storage and Database, also provide the username and password for the MySQL database which you created in the previous steps.

Once you have entered the configuration information, click on the Finish Setup button. Once the configuration is completed, you should see a welcome splash screen as shown below:

OwnCloud home page

Summary

Congratulations! You have successfully installed OwnCloud with SSL support. Feel free to comment below or open a discussion in the Community section if you have any questions.