by Ivan Voras
This article is to walk the participant through the installation and the basic configuration of ownCloud, an excellent open source collaboration and file sharing application written in PHP.
OwnCloud is a well-featured collaboration application
whose greatest features are:
• Extensive file sharing options: via the web interface, or via a DropBox-like desktop synchronization tool, or over the built-in WebDav server
• Document collaboration with simultaneous real-time editing of documents similar to Google Docs (though much less featured for now)
• A calendar and an address book, accessible from third party application by using the CalDav protocol
• An extensive architecture which allows plug-ins and additional applications to be included in the framework of the main application
In practice, its main selling point is the DropBox-like functionality with client applications available for Windows, Linux, Android and iPhone devices.
ownCloud requires a database which it will use to store metadata such as version information, and also system data and content for some types of resources. Depending on the type and frequency of its users, it could require approximately between 10 MB and 100 MB of database data per user per year. This article will use MySQL for its database for this and other applications, primarily because FreeBSD still has problems with UTF-8 collation required by PostgreSQL.
Installing MySQL
MySQL has a reputation for being simple, and it actually is. For this article, we will install MySQL version 5.5:
# pkg install mysql55-server mysql55-client
Updating FreeBSD repository catalogue:
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 2 packages will be affected (of 0 checked). New packages to be INSTALLED:
mysql55-server: 5.5.40 mysql55-client: 5.5.40
The process will require 105 MB more space. 8 MB to be downloaded.
After the installation, it simply needs to be configured and enabled in /etc/rc.conf
, by adding lines such as the following:
mysql_enable=”YES” mysql_dbdir=”/srv/mysql”
Before MySQL can be started, the database directory specified above needs to be created and appropriate permission given:
# mkdir /srv/mysql # chown mysql:mysql /srv/mysql
It is also useful at this point to create a MySQL configuration file, name my.cnf and located in /usr/local/etc
. This file can contain lines such as these:
[mysqld] key_buffer = 128M thread_concurrency = 4 query_cache_type = 1 query_cache_size = 128M innodb_file_per_table = 1
MySQL is very customisable and supports a huge number of configuration options. The options in the above example specify the key buffer size of 128 MiB, that 4 threads will be used to serve queries, activate the query cache and set its size to also 128 MiB (the settings are unrelated). All of these settings are useful for increasing the database performance, but the official MySQL documentation should be studied to understand their full effects. The last line specifies that individual tables in the database will be saved as individual files in the database directory, which is extremely useful for backups and maintenance. After the configuration file is created, the database can be started by issuing:
# service mysql-server start
The first time MySQL is started it will create its required files.
Installing ownCloud
ownCloud is a PHP application whose source needs to be downloaded and unpacked in an appropriate directory on the server. It can be downloaded from http://owncloud.org/, for example with the following commands:
# cd /srv/www # fetch –no-verify-peer https://download.owncloud.org/ community/owncloud-7.0.2.tar.bz2 # tar xzf owncloud-7.0.2.tar.bz2
ownCloud requires that use which executes its code (the PHP interpreted, started by mod_fcgid in Apache as the “www” user) can write to some of its directories. We can adjust the permissions like this:
# cd /srv/www/owncloud # mkdir data # chgrp www apps config data # chmod 0770 apps config data It also requires some dependency packages: # pkg install php5-exif php5-openssl php5-mysql php5-gd php5-ctype php5-dom php5-json php5-xml php5-simplexml php5-zip php5-zlib php5-bz2 php5-curl php5-mcrypt peclintl php5-fileinfo pecl-APC php5-mbstring php5-iconv php5-pdo php5-pdo_mysql mp3info php5-session
The next step is to create the MySQL database which will be used by ownCloud. To do this, simply run “mysql” as the root user and run the create database and grant commands at its prompt:
# mysql
Welcome to the MySQL monitor. – Commands end with ; or g.
Your MySQL connection id is 1 Server version: 5.5.40 Source distribution Copyright (c) 2000, 2014, 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 developers.
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current
input statement.
mysql> create database owncloud; Query OK, 1 row affected (0.02 sec) mysql> grant all on owncloud.* to ‘owncloud’@’localhost’; Query OK, 0 rows affected (0.00 sec)
Conclusion
Finally, the Apache virtual host configuration can be updated. For this tutorial, we will only add ownCloud to the HTTPS virtual host of our default configuration file, which will now look like this:
<VirtualHost *:443> ServerAdmin ivoras@gmail.com ServerName www.ivoras.net ServerAlias ivoras.net ErrorLog “/var/log/http-default-error_log” CustomLog “/var/log/http-default-access_log” combined DocumentRoot “/srv/www/default” <Directory “/srv/www/default”> Options ExecCGI FollowSymLinks AddHandler fcgid-script php FCGIWrapper /usr/local/bin/php-cgi .php DirectoryIndex index.php AllowOverride None Require all granted </Directory> Alias /cloud “/srv/www/owncloud” <Directory “/srv/www/owncloud”> Options ExecCGI FollowSymLinks AddHandler fcgid-script php FCGIWrapper /usr/local/bin/php-cgi .php DirectoryIndex index.php AllowOverride All Require all granted </Directory> SSLEngine on SSLCipherSuite !ADH:!EXPORT:!SSLv2:EECDH+aRSA+AESGCM:RC4+R SA:+HIGH:+MEDIUM:+LOW SSLHonorCipherOrder On SSLCertificateFile /var/ssl/ivoras.net.crt SSLCertificateKeyFile /var/ssl/ivoras.net.key </VirtualHost>
Apache needs to be restarted after the modification of the configuration file and the installation of new PHP modules:
# service apache24 restart
The first time the web site is visited with an URL such as https://ivoras.net/cloud, ownCloud will offer a simple configuration interface which must be used to create the initial administration user and to configure the database, which needs to be filled in as shown in the following image:
If the configuration is successful, you will be taken to the list of initial example files in ownCloud. Note than ownCloud has a large number of features so you need to study its interface and its user manual to know how to use it well.
ABOUT THE AUTHOR
Ivan Voras is a FreeBSD developer and a long-time user, starting with FreeBSD 4.3 and throughout all the versions since. In real life he is a researcher, system administrator and a developer, as opportunity presents itself, with a wide range of experience from hardware hacking to cloud computing. He is currently employed at the University of Zagreb Faculty of Electrical Engineering and Computing and lives in Zagreb, Croatia. You can follow him on his blog in English at http://ivoras.net/blog or in Croatian athttp://hrblog.ivoras.net/, as well as Google+ athttps://plus.google.com/+IvanVoras.