Wednesday, 27 February 2013

Installing ownCloud on Debian GNU/Linux using Git

I have been watching an open source project for a while now with great interest.   The name of the project is ownCloud and it is a file synchronising server with a web interface that operates much the same as Dropbox, SkyDrive, iCloud and other cloud based storage solutions.
Now that ownCloud is feature rich and has a client for Android, iOS, Windows and OS X, I wanted to install it to move my cloud storage away from Dropbox and onto my own server. By doing this I will have control of my data without the need to pay for space and more flexibility as to how I access my data.

I am a fan of the GNU/Linux distribution called Debian so I installed a virtual machine running Debian Wheezy release candidate to host ownCloud. You can install ownCloud on Windows Server if you wish. The stable version of ownCloud on their website is at v4.5 which has issues using external storage on a Windows shared folder, so I needed to install the latest beta version.

To get the latest version of ownCloud I needed to install using the Git repository from GitHub. At the time of writing this article the ownCloud version on GitHub is at v5.0 beta 2.

To start off with I needed to install the prerequisites on Debian with this command;
apt-get -y install apache2 php5 php5-gd php5-json php-pear php-xml-parser php5-intl php5-sqlite curl libcurl3 libcurl3-dev php5-curl smbclient cifs-utils mp3info zip git

At this point, I changed the php.ini file to increase the upload_max_filesize value from the default 2M to 1024M;
vim /etc/php5/apache2/php.ini

I decided to install ownCloud into the root of the apache2 www folder;
cd /var/www

I removed the original apache2 index file;
rm index.html

To get the latest ownCloud version I needed to use Git to clone the core, 3rdparty and apps repositories into the root of the web server.   Note that the apps clone needs to be cloned into a new target apps2 directory to prevent conflicts with the core repositories apps folder. I will need to edit the config.php file later to include the apps2 folder, but it does not exist yet;
git clone ./
git clone
git clone apps2

Now I need to give ownership of the ownCloud directories to www-data with;
chown -R www-data:www-data ./*
chown -R www-data:www-data /var/www

To improve the security of ownCloud I needed to enable .htaccess in the virtual host file;
vim /etc/apache2/sites-enabled/000-default

Now change the /var/www directory element so AllowOverride is set to 'All' as in this example;
<directory var="" www="">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all

I found when I first tested this install approach the Admin page reported a locale issue so I needed to install the en_US.UTF-8 locale for the system to work correctly with file names. My default locale is en_AU.UTF8. To install the US UTF8 locale run this command;
dpkg-reconfigure locales

Then select the US UTF-8 locale.
Check the installed locales with;
locale -a

Lastly enable the following modules and restart apache2;
a2enmod rewrite
a2enmod headers
service apache2 restart

I can now open a web browser and access my ownCloud instance (http://ServersIPAddress/) but there is an expected error.   When I first connect to ownCloud like this it will create a config.php file.

Now that I have an ownCloud config file I need to edit it to support the apps2 directory. If you read on the apps repository page here (near the bottom) it states the need for this change. When you edit the config.php file using the instructions from the link above it states to leave the apps and apps2 directory as writable = false. This failed on my install and I needed to change writable to true on the apps2 directory for user downloaded apps;
vim /var/www/config/config.php

Here is my complete config.php file;
$CONFIG = array (
  'instanceid' => '512efd12eb6d8',
  'passwordsalt' => '5555c4f3a4fbeb1a527d376095555',
  'datadirectory' => '/var/www/data',
  'dbtype' => 'sqlite3',
  'version' => '4.94.10',
  'installed' => true,
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/apps',
      'url' => '/apps',
      'writable' => false,
    1 =>
    array (
      'path' => '/var/www/apps2',
      'url' => '/apps2',
      'writable' => true,

I can now connect to my new ownCloud server and run through the setup wizard to create the SQLite database and admin user.

I now have a working cloud storage solution!

To update to the latest Git version I will need to run these commands;
cd /var/www
git pull
cd /var/www/3rdparty
git pull
cd /var/www/apps2
git pull

There is more to do such as enabling SSL and mapping to my external shared folder running on Windows but that is another story.

Here are the references I used to complete this task;   (ownCloud github site)   (v5.0 installation documents)   (fixing the US UTF-8 issue)

To use port SSL use this reference to enable it on Apache2 with Debian;

No comments:

Post a Comment