Install OwnCloud on your Raspberry Pi

Owncloud Logo

OwnCloud is a free (libre), open source equivalent to DropBox.

As well as the program you install on your server, it has free desktop sync clients for Linux, Windows and Mac, and apps for Android and iOS.

I’m just going to cover the server side of things for your Pi in this tutorial, because the desktop client can be found in the Ubuntu repos, and the app is on the Play Store. If you want the Android app free of charge, then install it via F-Droid.

First, install Apache 2 and some other bits.

These are all the bits you need to install before you can run OwnCloud.

sudo apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
sudo apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl

Next, Download and Install OwnCloud

If you visit the Owncloud installation page here, you will find the installation file.

Choose “Tar or Zip File” under the server heading.

OwnCloud intsallation download page

Now copy the link address of .tar.bz2 file (you can do this by right clicking and choosing “Copy Link Address” in Chrome or Chromium). At the time of writing, this address is http://download.owncloud.org/community/owncloud-5.0.12.tar.bz2, but it will change when a new version comes out, so it’s worth checking.

Save the address of the UNIX .tar.bz2 file (right click, copy link address in Chrome)

Save the address of the UNIX .tar.bz2 file (right click, copy link address in Chrome). Now, open a secure shell (SSH) into your Pi, and download the file:

wget http://download.owncloud.org/community/owncloud-5.0.12.tar.bz2

The zip file will be downloaded to your home directory (unless you were in some other directory before you ran that command, in which case it will be in there). Now extract the .tar file:

tar -xjf owncloud-5.0.12.tar.bz2

You will now have a sub-directory in your home directory called owncloud. Copy it to Apache’s data directory:

cp -r owncloud /var/www/

This will copy all your owncloud stuff into a directory at /var/www/owncloud, meaning that your owncloud website will be located at yourdomain.com/owncloud/.

Optional: Move OwnCloud to the Root Apache2 Directory

If you would like owncloud to be on the root of your domain (i.e. yourdomain.com takes you straight to owncloud) then you can move the contents of /var/www/owncloud up a directory into /var/www/ with the following command:

cd /var/www/
sudo find owncloud -maxdepth 1 -mindepth 1 -exec mv {} . \;
sudo rmdir owncloud

I got that handy tip from this website, check it out for a great explanation.

A Few Final Touches

Now, make sure that Apache owns all of those files you just added:

sudo chown -R www-data:www-data /var/www/

Now open your Apache virtual host file and change it to enable .htaccess files for OwnCloud (this is necessary so that OwnCloud can do things like override the global maximum file size for uploads):

sudo nano /etc/apache2/sites-enabled/000-default

Change AllowOverride None to AllowOverride All in the Directory /var/www/ section of the file.

Now check if an .htaccess file for OwnCloud exists. If it doesn’t, create it:

cd /var/www/ #use /var/www/owncloud if you didn't move it to /var/www/
ls -al
#look for .htaccess. If it exists, skip the next two lines
sudo touch .htaccess
sudo chown www-data:www-data .htaccess

Now run the following two commands to enable some apache modules, and restart apache2:

sudo a2enmod rewrite
sudo a2enmod headers
sudo service apache2 restart

Port Forwarding and DNS

If you want to access your ownCloud installation from outside your LAN, you'll need to forward ports 80 and 443 (for HTTP and HTTPS) to the Pi from your router.

If you haven't done this already, you may want to use my tutorials to set up a DNS A record to map your domain name to your public IP address, and make use of ddclient to update your DNS records when they change if you have a dynamic IP address.

Testing

Test your installation, by visiting your server’s URL. Either use http://yourdomain.com/owncloud if you didn’t move owncloud to Apache’s root directory, or http://yourdomain.com if you did.

You should be greeted with an installation wizard.

Owncloud database drivers error

If you get an error about database drivers, then try installing php5-mysql again – for some reason, it didn’t install properly first time for me, although no errors were shown:

sudo apt-get install php5-mysql
sudo reboot

You should no longer see the error if you visit the page again.

Database Username and Password

The OwnCloud installation wizard will ask you for a database username and password.

If you haven’t set up any other databases on this server before (and therefore don’t have a root database user and password) then you will have to create a root database username and password before you can continue. If you are already using software that uses databases (like WordPress) then you probably already have a database root username and password, and can skip this step.

Install mysql server and client:

sudo apt-get update
sudo apt-get install mysql-server mysql-client

The package installation will bring up a configuration wizard. Enter the username you’d like to use, and a password. Write these down, you’ll need them later.

Now you can complete the installation. Go back to your browser with the OwnCloud setup wizard, and choose a username and password for your OwnCloud user account. You also need to enter the database root username and password, and choose a name for the OwnCloud database (“owncloud” will do). The database location is localhost.

Some extras

1) Cut Page Loading Times with a PHP Cache

PHP is a server side scripting language. When you request a page on the server, the server has to compile the page from the PHP source.

Because your Pi is such a low powered machine, this can be really slow.

Luckily, there’s a PHP cache you can use that will store a pre-compiled copy of pages in your RAM after they have been visited already. This makes a MASSIVE difference – before installing the cache, it took 21 seconds to load the index page, afterwards a mere 7-8 seconds.

Install it by using this command:

sudo apt-get install php-apc

Now restart the Apache web server using:

sudo service apache2 restart

The first time you visit a page may be slow, but if you navigate away and then come back to it you should notice a significant improvement.

Thanks to Steve Riley at Kubuntuforums for this tip.

2) Put all your data on an external hard drive

If you have moved your Pi’s root filesystem to a USB flash drive then you may have enough storage to use OwnCloud as it is.

However, one of the main advantages of using OwnCloud instead of Dropbox is that you can easily plug in as many hard drives as you like and wave goodbye to that 5GB storage limit.

I attached a self-powered 500GB hard drive to mine, and it works beautifully. Remember, the Pi doesn’t have enough power to run a passport drive without an external hub to provide power.

Before we start, format your hard drive with a journalling filesystem such as ext3 or ext4.

First, make the directory ready to mount your drive:

sudo mkdir /media/owncloud

Plug in your drive to your Pi, and type:

sudo blkid

Make a note of the output for the device you want to mount. Here’s an example (it’s for one of my laptop’s partitions, hence /dev/sda6, yours will be a whole drive, e.g. /dev/sdX)

/dev/sda6: LABEL="Data" UUID="f052e620-9e88-4b19-9b9a-d6dce4d6603b" TYPE="ext4"

Now edit the file /etc/fstab, which controls how and where drives are mounted at boot.

sudo nano /etc/fstab

Edit the file so it looks something like this, but replace my UUID with yours and update the filesystem type from ext4 to whatever you are using if necessary:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID="96f64567-c459-4d3d-9f52-e6aabee544d2"     /media/owncloud         ext4    defaults    0       2
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

Now reboot the Pi and check your drive is mounted properly:

cd /media/owncloud
ls -al

Stop Apache2:

sudo service apache2 stop

Now we need to move Owncloud’s data directory, and create some symbolic links so that the rest of Owncloud still knows where to look for data.

Where you’re moving stuff from depends on whether or not you moved owncloud to Apache’s root (/var/www). If you did move it, then owncloud is currently installed at /var/www; if you didn’t move it then it’s in /var/www/owncloud.

I’m going to assume that you did move Owncloud. If you didn’t, then you need to insert /owncloud after /var/www in each of these steps.

Move /var/www/data to /media/owncloud:

sudo mv /var/www/data /media/owncloud/data

Create a symbolic link to the new owncloud directory.

sudo ln -s /media/owncloud/data /var/www/data

Now do the same for the config folder:

sudo mv /var/www/config /media/owncloud/config
sudo ln -s /media/owncloud/config /var/www/config

Now check that the ownership of the moved files is Apache (www-data):

sudo chown -R www-data:www-data /media/owncloud

Now start Apache2 again:

sudo service apache2 start

Any data you now upload should go in your external hard drive.

I owe thanks to Steve Riley (again!) at OwnCloud forums for this one.

3) Force SSL (https) Connection

You can force your users to connect to OwnCloud using an HTTPS connection.

Simply change the virtual hosts file for apache2 to enable .htaccess as before: open /etc/apache2/sites-available/default-ssl and change AllowOverride None to AllowOverride All under the Directory /var/www/. Make sure you have the line SSLEngine on, and your SSLCertificateFile and SSLCertificateKeyFile point to the certificates you’d like to use.

Now enable the Apache SSL module:

sudo a2enmod ssl

Enable the SSL site:

sudo a2ensite default-ssl

Reload Apache:

sudo service apache2 reload

Now visit https://yourdomain.com/owncloud if you didn’t move apache to your root, or https://yourdomain.com if you moved owncloud to your root directory.

Using the drop-down menu, navigate to admin –> admin, and under the Security header, tick the Enforce HTTPS box.

Check the Enforce HTTPS box

Note that you will only be able to do this if you are connected with https (otherwise you’d lock yourself out!)

All done. Now all your communications between the client machines and your server will be encrypted. If you try to visit the http version of OwnCloud, you will be redirected to https.

If you don't already have a SSL certificate, you may want to generate your own and get it signed by CAcert for free.

Hope you found that useful. If there’s anything else you’d like to know, leave a comment!

Type: 

Comments

Great tutorial :) I have setup my own ownCloud (using a pre-made img) however I would like to use https but am somewhat confused. Where do I get the SSLCertificateFile and SSLCertificateKeyFile from?

Thank you for any help you can provide :)

Hi Kevin,

Thanks for commenting! You should already have a self-signed SSL certificate that Apache auto-generated during installation. They are stored here:

SSLCertificateFile        /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile        /etc/ssl/private/ssl-cert-snakeoil.key

It's called a "snakeoil" cert because it's self-signed, and the common name on the certificate doesn't match your domain so you'll get security errors in your browser. It will work fine for testing, though.

You can generate your own SSL cert with a common name that matches your site and get it signed by CAcert for free later (see this tutorial of mine).

If you go to https://yourdomain do you see owncloud? If not you may need to enable the default-ssl virtualhost and the apache ssl module.

Take a look at this other tutorial I wrote for information on Apache's virtual host configuration files, it should help you understand what's going on here.

Sam

Where the box for https thing is meant to be its not there what should I do?

ownCloud has had three major revisions since I wrote this, so lots has changed, and that option has been removed.

Redirect in your virtualhost file instead, like this:

<VirtualHost *:80>
   ServerName cloud.owncloud.com
   Redirect permanent / https://cloud.owncloud.com/
</VirtualHost>

See this virtualhost tutorial for more info on apache configuration.

You also asked about linking it to a domain name. Check out my DNS basics tutorial for that (you need to point your DNS A record at your Pi). If you have a dynamic IP address, you can use the guide I wrote for ddclientl to set it up to auto-update when your IP address changes.

Sam

Hello, thanks for the tutorial. This is a noob question, sorry. I already installed LAMP and configured as a personal web page, I am hosting it myself using no-ip. Can I also configure it for owncloud and not interfere with my current web page? Any help or suggestions would be greatly appreciated.

thanks

Hi Javier,

Yes you can do that. Your apache data directory is /var/www so typically you would put a subdirectory in there for each application, i.e. /var/www/owncloud holds all your OwnCloud files, and /var/www/wordpress or /var/www/drupal holds your website files. Then you tailor your virtual host files so that each one points to the right subdirectory as its document root.

What software are you using at the moment, and where is it stored in /var/www? The one thing you should watch for is that if your main website files are in the root of Apache's data directory (not in a subdirectory) and you install owncloud to /var/www/owncloud then you will be able to access owncloud by going to yourdomain.com/owncloud (which may be what you want). If it isn't what you want then you'll need to tinker with your virtualhost file for the website to deny access to owncloud from within it, and add a separate virtualhost file to serve owncloud on owncloud.yourdomain.com, for example.

You might find this useful:
http://www.samhobbs.co.uk/2014/01/multiple-websites-and-subdomains-with-ssltls-in-apache2-virtualhosts

If you're still confused after reading it then please ask another question and I'll do my best to help you out!

Sam

Thanks for your quick response. I was able to install owncloud but when I get to the wizard it asks for a user and password for sql that I was never prompted to create. I checked various sites on how to create or reset root password using mysqld_safe --grant-skip-tables but I still get invalid user/password error in owncloud wizard after I supposedly reset the password. I am still trying to figure it out, however, do you know or is there a way uninstall owncloud and mysql to start from scratch in the event that I can't figure it out? I know I must have missed a step and probably will be good idea to start over.

thanks

Well, you could try:

sudo dpkg-reconfigure mysql-server

And then follow the instructions under the "Database Username and Password" section. That would bring up the configuration wizard again, where you can set the mysql root password.

BUT - you mentioned that you has "already installed LAMP and configured as a personal web page" - if you're using a content management system like WordPress or Drupal then that piece of software is using the mysql server already, so reconfiguring it may break it. If you just meant you're using static HTML then you'll be fine.

Sam

Ok so I tried dpkg reconfigure but when I tried resetting password I kept getting access denied need at least one super user property or something like that. So I found another site with instructions on how to completely remove sql using sudo apt-get remove. I then reinstalled and I did get the prompt to create a new password for root this time. Now, when I go to owncloud on the page there is a message No database drivers installed. I'm still trying to figure it out. I'll let you know how I fixed it if I figure it out..lol.

thanks again!

Perhaps you didn't use sudo to run the dpkg-reconfigure command? Superuser = root. You temporarily gain superuser privileges when you use sudo.

If you want to do it the "completely remove and reinstall" way, then to remove configuration files as well you have to use the purge option:

sudo apt-get remove --purge mysql-server
sudo apt-get install mysql-server

As for the database driver, did you see the part of the tutorial where I mentioned that error? Try:

sudo apt-get install php5-mysql

Sam

Yes, I went over your tutorial again and saw that you had instructions for that issue and it fixed it! Owncloud is now working locally on the pi however, I get an error 'You are accessing server from an untrusted domain' when I try to access from within the network and from outside lan. I am fiddling around with the config.php file but so far no luck.

I haven't seen that error before. Sounds kind of like an SSL error - Apache uses a self-signed certificate by default unless you tell it to use a different one, and your browser doesn't trust self-signed certs unless you make an exception. Could be that.

Could you take a screenshot, upload it somewhere (e.g. imgur, photobucket) and paste a link?

I think its specific to version 6. I got it up and running and it's working perfectly now! There's a line in the config.php file that states the trusted domains...when you first configure it it only writes the local loopback 127.0.0.1in the config file as a trusted domain. Initially it only works on the local machine. You just have to edit the file and add the url of the domain you are using and add it to trusted domains in the config.php file.
Here's the link of you're interested for future reference..https://forum.owncloud.org/viewtopic.php?f=17&t=20220.

Thanks again for all of your help, I greatly appreciated!

I see! I'm sure other people setting up will find that useful, thanks for providing a link.

I'm using version 6.0.3 at the moment, but it's a version that has been upgraded a couple of times. I can't find a trusted domains setting in mine anywhere, presumably it would be there if I did a fresh installation.

Glad it's all working now!

Sam

Hi Sam, thank you for a terrific guide. I switched /var/www/owncloud up a directory into /var/www/ with the command you listed. But after some consideration I would like to switch it back, how would I do that without fucking things up?

Hi Sam! Thanks for writing out a great tutorial!

Is a journalling file system required to use an external hard drive? I have existing data on my hard drive (4TB WD MyBook) and have nowhere to store it in order to reformat. Could I follow your steps without formatting it to ext3 or ext4, and still be successful?

Thanks!

Hi Vanessa!

A journaling filesystem is just one that writes what it's about to do to a journal before it does it, so that if it's interrupted in the process by a power failure or similar (between different stages of the operation), it's easier to recover instead of leaving the operation half finished. It's not essential, but would be a nice thing to have, particularly as the power supplies to Raspberry Pi can be flaky.

On the other hand, filesystems like NTFS do not support unix-like permissions (rwx etc.). If I remember correctly, in Windows the information about who can read & write to the files is stored in the registry, not in the filesystem itself. So if you put all your data on the HDD on a filesystem that doesn't support permissions I don't know what will happen. Maybe nothing, but maybe all processes on the RasPi would have access to all of the files, which is not ideal.

How much data is on that drive? The simplest thing may be to make a second partition on it in the spare space (EXT4, for example) and just mount that specific partition at /media/owncloud instead of the whole drive.

You could also create the new partition on the drive, copy everything over from the old one, delete the old partition and move the new partition back to the start of the disk, but this would take absolutely ages (you can extend partitions forwards into free space on a disk really easily, but going backwards takes ages and requires everything to be re-written).

Sam

Awesome, thanks for the info!
I have about 1.5TB of data on the drive already. I think I'm going to try to partition it out. Worse comes to worse, I'll find some temporary space on other drives or clouds so I can format it.

Hi Sam

First off all thanks for the walk through, great bit of learning for a newbie like myself.

I've ran into a couple of issues trying to complete this and was wondering if you could help:
a) cannot connect through a safe connection to my domain, it is possible through http but am less keen to use this as a result of the safety concerns. I have not yet applied for a ssl certificate but in theory should be able to connect prior to doing this. I'm guessing the problem is in my sshd_config file but nothing stands out
b)Is there any way of exceeding the 2GB file upload limit?
c)is there any way of transferring files from a windows hard drive to a ext3 or ext4. the files I would like to have on the cloud are significantly large (500G) and uploading each one through owncloud would take significant time.

Thanks
L

You're welcome.

Can I just check you've followed the steps for forcing HTTPS? You're right that you should be able to connect with the default "snakeoil" cert.

I think you've mixed up SSH (secure shell, remote commandline interface) and HTTPS (encrypted HTTP). HTTPS doesn't have anything to do with your sshd_config file, which is for your SSH server (read sshd as "secure shell daemon") config file.

Have you forwarded port 443 to your pi from your router?

You can set a higher file upload limit by clicking on your name when logged in (top right) and selecting admin... there is a section called "File handling" where you can set any upload size you like.

Writing to EXT3 or EXT4 is possible from Windows, but I'm not sure if adding files to ownCloud is as simple as adding them to a folder, I think they need to be added to the database too. Could be wrong though.

Hope that helps!
Sam

Hi!

How can I completely remove owncloud and everything that it came with? I think it's to slow for the RPi, maybe because it's not dedicated only to owncloud.... :D What is it that I should and can remove that it's not used by mail or webserver?

Assuming your owncloud directory is here... delete /var/www/owncloud with this command:

sudo rm -r /var/www/owncloud

Then go to phpmyadmin (covered in my wordpress tutorial) and delete your owncloud database.

If you put your owncloud data files somewhere strange then you'll need to remove those too.

If you mean packages... that's a difficult question (we didn't install owncloud using apt, or we could just use apt to uninstall owncloud and let it worry about the dependencies). Those bits we installed with apt at the start (under the First, install Apache 2 and some other bits. header) are now set to manually installed because we named them specifically, which means apt won't autoremove them. You could remove them by naming them but that may cause problems if wordpress or something else needs them (wordpress definitely needs one of the php modules to connect to the database, for example). To be honest, I wouldn't worry about removing the packages, they won't do any harm.

Sam

This was a great tutorial! Well written and highly detailed. I followed the steps and was able to setup an owncloud server on my Raspberry Pi. Thanks again!

Hey great tutorial Sam...
When i started owncloud for the first time.. It directly started off and i haven't anytime previously created a MySql Database ...
where can I see the details pertaining to the database on my Pi.

Pages

Add new comment