web analytics

How to Set Up OwnCloud on Ubuntu 14.04 LTS Server (Part I)

Note: This blog was originally posted as one single entry. However, I feel that the installation and security setups are seperate issues, so please refer to How to Set Up OwnCloud on Ubuntu 14.04 LTS Server (Part II) for Hardening Security Practices.

Per suggested by ownCloud admin manual, the graphical Installation Wizard is the most convienent way of configuring ownCloud. However, I managed to connect to the server via SSH, thus I can only initialize and configure ownCloud from the command line. Here are the steps in a nutshell:

1. Install ownCloud from the command line

Download and install the ownCloud code via package manager, or download and unpack the tarball in the appropriate directories. Follow the official instructions will be the best practice. For example, to install owncloud-8.2.2-1.1 on the Ubuntu 14.04 using apt, we can add the following repository key and install:

# wget -nv https://download.owncloud.org/download/repositories/stable/Ubuntu_14.04/Release.key -O Release.key
# apt-key add - < Release.key
# sh -c "echo 'deb http://download.owncloud.org/download/repositories/stable/Ubuntu_14.04/ /' >> /etc/apt/sources.list.d/owncloud.list"
# apt-get update
# apt-get install owncloud

2. Complete installation

First change the ownership of the owncloud directory to your HTTP user:

# chown -R www-data:www-data /var/www/owncloud/

Then change to the root ownCloud directory (/var/www/owncloud/), and use the occ command to complete the installation. This takes the place of running the graphical Installation Wizard:

$ cd /var/www/owncloud/
$ sudo -u www-data php occ maintenance:install --database "mysql" --database-name "owncloud"  --database-user "root" --database-pass "password" --admin-user "admin" --admin-pass "password"

Here, we use the mysql as the database and you can choose one in mysql/sqlite/pgsql/oci. We also created the admin user admin and this name is UNCHANGEABLE in later time! Also pay attention to the passwords.

Caveat You should locate your ownCloud data directory outside of your Web root if you are using an HTTP server other than Apache, or you may wish to store your ownCloud data in a different location for other reasons (e.g. on a storage server). This data directory must already exist, and must be owned by your HTTP user. Use the --data-dir in the installation commands instead:

$ cd /var/www/owncloud/
$ chown -R www-data:www-data /path/to/oc-data/
$ sudo -u www-data php occ maintenance:install --database "mysql" --database-name "owncloud"  --database-user "root" --database-pass "password" --admin-user "admin" --admin-pass "password" --data-dir "/path/to/oc-data/"

3. Basic configurations

Edit /var/www/owncloud/config/config.php and add your website domain to the trusted domains section, so that ownCloud will not give you a warning on its startup:

'trusted_domains' =>
array (
	0 => 'localhost',
	1 => 'your.domain',
),

Basic configurations are stored in config.php file where you can find detailed instructions from the ownCloud official manual.

4. Place data directory outside of the web root

Per suggested by ownCloud official manual, it is highly recommended to place your data directory outside of the Web root (i.e. outside of /var/www/). It is easiest to do this on a new installation as explained in the previous section.

If you (unfortunately) decide to move the data directory to another place after the above configuration (like I did), it is achievable. First, stop your webserver, and you need to change or create the “datadirectory” entry in /var/www/owncloud/config/config.php file, so that it points to wherever you want to have your data from now on. Assuming the directory you want to move the data folder to is ‘/path/to/oc-data’, your config.php should look like this after the change:

$CONFIG = array (
  'datadirectory' => '/path/to/oc-data/',
  'dbtype' => ...
  )

Then, move the data directory to the desired place:

# mv /var/www/owncloud/data /path/to/oc-data
# chown -R www-data:www-data /path/to/oc-data

Make sure the permission/ownership of the new folder is set up correctly, by verifying that the webserver can read the directory

$ sudo -u www-data ls -lisa /path/to/oc-data/

Then you can restart your webserver (e.g. sudo service apache2 restart on Ubuntu).

5. Optimize ownCloud performance through caching

PHP 5.5 and up includes the Zend OPcache in core, and on most Linux distributions it is enabled by default. However, it does not bundle a data cache. APCu is a data cache, and it is available in most Linux distributions. On Ubuntu we should install php5-apcu.

Yet the trick is that ownCloud 8.0+ requires the version of APCu must be 4.0.6 and up. If you use sudo apt-get install php5-apcu on Ubuntu 14.04 LTS, the installed APCu version is 4.0.2, so that the ownCloud still throws warning. After quite some time of research, I finally find the solution. Just as simple as invoke the following command will install APCu 4.0.7 found in Please backport php5-apcu version 4.0.6 to Ubuntu 14.04 LTS:

$ sudo apt-get install php5-apcu/trusty-backports

Of course if you are uisng Ubuntu 15.04 or later version, it is easier:

$ sudo apt-get install php5-apcu

Then, configure the ownCloud in /var/www/owncloud/config/config.php, adding

'memcache.local' => '\OC\Memcache\APCu',

Also, enable APCu in your PHP config file:

# Filename: /etc/php5/php.ini

[APC]
extension	= apc.so
apc.enabled = 1

and restarting your web server, and refresh your ownCloud admin page, and the cache warning should disappear.

Creative Commons License
This work by Zengwen Yuan is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
comments powered by Disqus