Monday, November 19, 2012

OwnCloud on Ubuntu. Media Server (miniDLNA). Remote Access

Recently I took a half an hour video using my Samsung S3. The video was approximately 3.6GB, which is  close to the upper limit offered by several publicly available cloud/ online storage services such as Dropbox, Google Drive, or Ubuntu One.

That is enough incentive for me to build my own private cloud, considering my 1.5TB harddrive is the only storage limitation and I have full ownership over its security.

OwnCloud Server

I came across OwnCloud, an open source, php web based software.

Owncloud is a centralized storage solution: the software automatically stores your files onto its server.

It also has its own clients for linux, windows, android etc, so it's quite flexible in my opinion.

On my ubuntu server running on 12.04.1 LTS (with LAMP stack), it's installation is simply:

root@ubuntu:/opt# apt-get install owncloud

At the time of writing, this gives you ownCloud version 3 (the latest version is owncloud 4), so keep in mind the compatible sync clients's version is 1.05

Upon successful installation, OwnCloud can be accessed via web interface http://server-ip-address/owncloud. All file upload, download and folder creation can be done here: 

OwnCloud Sync Clients
OwnCloud's web interface allows for max of 2MB upload, I understand this as a PHP limitation. 

OwnCloud has several sync clients available for different OSes, which don't have such limitations. So far I have tried two clients (both version 1.05 for Windows and Linux respectively) with the following findings:

1. Windows 8

Upon first setting up owncloud clientsync account, I encountered this client and server timing out of sync error. This prohibits the server and client to synchronize their files.

As a work around, I have set up the Ubuntu server as an NTP server. Then I pointed my windows machine towards it. 

For reference:
# apt-get install ntp

Start/ stop NTP
# /etc/init.d/ntp --help
Usage: /etc/init.d/ntp {start|stop|restart|try-restart|force-reload|status}

As client
# ntpdate

(In all fairness, it turned out the Windows machine was configured to the incorrect timezone, hence prohibiting it from synchronizing with the server).

2. Ubuntu Laptop LTS 12.04
Having installed the ownCloud sync client on my netbook, I have encountered no synchronization issues (apparently the netbook already has a public NTP working properly). 

I have left my netbook switched on allowing it to be sync for the entire day. Did a tcpdump to confirm there are https traffic being exchanged between the client and server.

The sync is finally successful. I suspect the initial sync took longer than the subsequent incremental updates. 

Home Access (miniDLNA)

Leveraging the Ethernet over Power setup I previously posted, it makes sense to enable DLNA on my OwnCloud server. This essentially converts my server to become a centralized storage, which allows for access from all devices via DLNA.

MiniDLNA is a light weight DLNA server software, which installation is as simple as running "apt-get install minidlna". A google search of "dlna ubuntu" returns this quick tip as its first result covering all the essential configurations. 

For my setup, by default, OwnCloud stores its client files in the following directory:
/var/lib/owncloud/data/root/files/ clientsync

In addition, I have also created a "music" and "photos" folders under the same directory. These directories are added to the media directories of minidlna (/etc/minidlna.conf)

# set this to the directory you want scanned.
# * if have multiple directories, you can have multiple media_dir= lines
# * if you want to restrict a media_dir to a specific content type, you
# can prepend the type, followed by a comma, to the directory:
# + "A" for audio (eg. media_dir=A,/home/jmaggard/Music)
# + "V" for video (eg. media_dir=V,/home/jmaggard/Videos)
# + "P" for images (eg. media_dir=P,/home/jmaggard/Pictures)

Notice I have set them as "A" for audio and "P" for images. 

At this point, if I run minidlna, the server returns an “Media directory not accessible!" error .

There is a post on the owncloud community forum describing the fix - by adding both root and minidlna users to the group www-data:
root@ubuntu:/opt# usermod -a -G www-data root
root@ubuntu:/opt# usermod -a -G www-data minidlna

Now, apply -R option to force a full rescan, before restarting minidlna:
root@ubuntu:/opt# minidlna -R

root@ubuntu:/opt# /etc/init.d/minidlna force-reload
* Restarting DLNA/UPnP-AV media server minidlna [ OK ]

/var/log/minidlna.log confirms file scan is successful:

[2012/11/17 14:23:26] minidlna.c:155: warn: received signal 15, good-bye
[2012/11/17 14:23:26] minidlna.c:907: warn: Starting MiniDLNA version 1.0.21 [SQLite 3.7.9].
[2012/11/17 14:23:26] minidlna.c:935: warn: Creating new database...
[2012/11/17 14:23:26] minidlna.c:1002: warn: HTTP listening on port 8200
[2012/11/17 14:23:26] scanner.c:719: warn: Scanning /var/lib/owncloud/data/root/files/music
[2012/11/17 14:23:26] scanner.c:790: warn: Scanning /var/lib/owncloud/data/root/files/music finished (166 files)!
[2012/11/17 14:23:26] scanner.c:719: warn: Scanning /var/lib/owncloud/data/root/files/photos
[2012/11/17 14:23:28] scanner.c:790: warn: Scanning /var/lib/owncloud/data/root/files/photos finished (1359 files)!

Remote Access
As mentioned earlier, there are largely two methods for ownCloud clients to access OwnCloud server - web access and sync client. 

There are some useful tweaks which enhance the security and ease of remote access:

1. Enhance security by enabling SSL (and redirecting all HTTP to HTTPS)

2. Enabling remote access by utilizing free dynamic dns services as covered in my earlier post

For example, rather than configuring https://Server-LAN-IP/owncloud, configure https://dynamicDNS-URL:some-random-port/owncloud as the owncloud server's address.

Stating the obvious, the dynamicDNS-URL is intended to be accessible via the public internet. That also means you can access your ownCloud from anywhere in the world with internet connectivity. 

Further notes
I recall enabling SSL on my Apache2 server involved a couple of steps, from creating SSL certificate to enabling the corresponding module in Apache2 software.
It is a worthwhile topic which I may write another post on when I get around to it. 


  1. Bluehost is definitely one of the best hosting company with plans for all of your hosting needs.

  2. Submit your website or blog now for appearing in Google and over 300 other search engines!

    Over 200,000 websites listed!



    Get professional trading signals sent to your mobile phone daily.

    Follow our signals right now and gain up to 270% per day.