Install OwnCloud on your Raspberry Pi

Powered by Drupal
Submitted by Sam Hobbs on

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!

Comments

I installed phpmyadmin and successfully removed(deleted) the owncloud database and users, but I see there's another database called mysql. Does that belong to owncloud too, or is it part of my email server (squirrelmail)?

Please advise.

Regards,

Jo

Jo, I don't know what that's for, but don't remove it - there's actually nothing wrong with having unused databases in there unless you want to use the same users and database names again (e.g. for owncloud) so just leave it. Sam

Hi Sam,

Thanks. I will leave it. Am I right in understanding that I must also re-install mysql again, or do I continue to use the previous root user and password I set up during the previous installation for mysql?

Please advise.

Regards,

Jo

Hi Sam,

Once again you have great tutorials!

Owncloud 9.1 successfully installed and tested inside and outside my LAN. 1TB HDD running smoothly!

Although everything is working great, I did see the following message at the top of Owncloud when I log in as admin:

There were problems with the code integrity check. More information...

When I click on the message it goes to a page that says Server Error. When I click on more details, it says:

The website encountered an error while retrieving https://pi-box.co.uk/owncloud/index.php/settings/admin#security-warning. It may be down for maintenance or configured incorrectly.

Any thoughts?

Regards,

Jo

Hi Sam,

No I'm not running modsecurity. Having researched online it seems to be an issue with a number of people running OC 9.0 and higher, but currently with no known fix...

I'll contact owncloud I think.

Thanks anyway.

Regards,

Jo

Hi Sam,

So this is a weird one which I'm not sure I still fully understand, but it works now!

After doing a lot of research/reading on various websites and forums about the "There were problems with the code integrity check. More information..." yellow banner at the top of OC when I log in as admin, I decided to re-install OC 8.2.2 because I still had the installation file on the Pi.

Upon re-installing I came across the same 'issue' (which I didn't know at the time was one)...just before Port Forwarding and DNS where I had to "sudo service apache2 restart". With OC 9.1 before and with OC 8.2.2 now, when I restarted I got a warning that said something like...it didn't work as expected...bla...bla...bla...try "systemctl daemon-reload" instead. I did it using the sudo command and it seemed to work when I did it with OC 9.1.

But with OC 8.2.2 when I tried to load owncloud in the browser, I got the same Server Error. I thought let me have a look online exactly what it is, and then found a host of people that had similar issues when restarting apache2. It seems to happen every time a reboot was performed and they had all sorts of ideas of how to overcome it by running scripts and things that included "systemctl daemon-reload" upon reboot. I tried "systemctl daemon-reload" and then "sudo service apache2 restart", and that seemed to restart apache2. I tried mydomain/owncloud again and this time no server error and I could continue with the install.

I then stopped before I got to the USB HDD part and decided to check if that was the issue with OC 9.1...so removed everything as per your advice earlier, re-installed OC 9.1, got to the restarting of the apache2 service, got the warning, did the sudo systemctl daemon-reload" and then restarted the apache2 service again...AND no yellow banner with "There were problems with the code integrity check. More information..."

So it may be that the two issues are related somehow, but I got it working properly! The only thing I need to remember is to "sudo systemctl daemon-reload" and then "sudo service apache2 restart" every time I reboot the Pi or figure out how to write a script that does it for me...

Hope this made sense to you and could be helpful in the future with others.

Regards,

Jo

Hi, Sam
Do you know this matter? I have install client tool on my macbook. Then, my server site's authority is what you mention all for www-data:www-data. I suffer a problem the client site tool give my a message when I create a file or directory on my sync folder. The message is this, "Not allowed because you don't have permission to add subfolders to that folder". I check my versions of owncloud on this file version.php which is inside of your main file location and know my version 9.1.3.1. I am not sure this is a bug. Otherwise, would you like to explain how to upgrade these manual installation tool? Really appreciate your devotion.
Best regards,
Jeff

I am just curious, what is the difference between Owncloud and Nextcloud (https://nextcloud.com/)? From what I can see one looks like a copy cat of the other visually. Nextcloud looks like it would be the exact same setup process that you have with Owncloud but with additional features not limited to Google Cal sync and many others. I may try to see if I can use the same instructions you have here to setup Nextcloud also (if indeed they are one in the same with coding)

By the way excellent write up as everything went smoothly with the setup on my RPi 3 and sharing away at home with 2TB of space.

Nextcloud is a fork of ownCloud, more focused on being a community platform instead of the ownCloud model, which had dual licensing for individuals and enterprise. If podcasts are your thing, you might find this interesting. I will be migrating to Nextcloud when I set up my home server again (just moved house!). Sam

I have moved over from OwnCloud to NextCloud ... WOW there is a ton of internal differences as far as plug-ins and apps go. All n 1 stop from your own home. Now what I would really like to do is some how move all my data from Google Drive over to the personal cloud but right now the only way I have any idea of doing so is downloading my G-Drive then uploading the contents manually unless someone knows how to do this with a script.

Hi Sam,
I encounter a weird thing. I don't know why my /dev/root this file system which is still remained on an increased size when I delete the files that had been uploaded. I used df -h to check the file system as below. Otherwise, I fellow your guide to make the symbolic link connect to the /media/owncloud. Would you know some clues? Thanks.


Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 19G 9.8G 66% /
devtmpfs 459M 0 459M 0% /dev
tmpfs 463M 0 463M 0% /dev/shm
tmpfs 463M 6.5M 457M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 463M 0 463M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 22M 42M 34% /boot
/dev/sda4 138G 60M 131G 1% /media/internal
/dev/sda2 321G 5.4G 299G 2% /media/owncloud
tmpfs 93M 0 93M 0% /run/user/109

Hi Sam,
I uploaded the files again and used df -h to show up the detail of file system. Please kindly refer to /dev/root and /dev/sda2. Both of them synchronically increased when I uploaded the files. Here I don't know why /dev/root also increased sizes on itself. I wonder there are some of files on /dev/root so that I try du -a this command to see them. There are lots of lines dumped on my eyes. Despite of these invisible files on /dev/root which may be found out by this command, I think there is a way to make it not occupy /dev/root and to occupy on /dev/sda2 only. Thanks


jeffadmin@raspijeffhost:/ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 16G 13G 57% / #===>Before.
devtmpfs 459M 0 459M 0% /dev
tmpfs 463M 0 463M 0% /dev/shm
tmpfs 463M 6.5M 457M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 463M 0 463M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 22M 42M 34% /boot
/dev/sda4 138G 60M 131G 1% /media/internal
/dev/sda2 321G 1.7G 303G 1% /media/owncloud #===>Before.
tmpfs 93M 0 93M 0% /run/user/109
tmpfs 93M 0 93M 0% /run/user/1001
jeffadmin@raspijeffhost:/ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 17G 12G 58% / #===>This increased /dev/root simultaneously with /dev/sda2
devtmpfs 459M 0 459M 0% /dev
tmpfs 463M 0 463M 0% /dev/shm
tmpfs 463M 6.5M 457M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 463M 0 463M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 22M 42M 34% /boot
/dev/sda4 138G 60M 131G 1% /media/internal
/dev/sda2 321G 1.9G 302G 1% /media/owncloud #===>This increased /media/owncloud simultaneously with /dev/root
tmpfs 93M 0 93M 0% /run/user/109
tmpfs 93M 0 93M 0% /run/user/1001

Hi Sam,
I found where the files occupied /dev/root. The modsecurity generated the modsec_audit.log simultaneously with owncloud when I uploaded the files. I used du -h and du -a to check it out. Then, I add "modsecrutiy" this file on "/etc/logrotated.d/". I think it can schedule this file to run out a proper result in the future.


/var/log/apache2/modsec_audit.log {
daily
missingok
rotate 1
compress
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null;
endscript
}

Sam, question for you, and hopefully you can answer it. I am not using SSL on my cloud system however Its pretty well secure and its only for family use. The question is how can I secure the data directory from being access on line... Example : http:// mycloud. ddns. net /data/ random users folder/ Is reachable. I need to be able to secure that portion down with out having to worry about SSL since I am using a dynamic IP address and my ISP does not provide residential users static IP addresses. Any help would be grateful!

You mean the data directory for owncloud is reachable as basic files without going through ownCloud? Sounds like a serious config problem, apache should be preventing that. Is .htaccess (AllowOverride) enabled for that virtualhost? Sam

I finally fixed it. I had to rebuild the entire conf file from the ground up. Old one for some reason had 2 VHs listed with the same site information plus some other items that were out of place. Sorry about your time Sam...but much appreciate the help.

I will check that out! One last thing (not really probably) I have tried to configure the upload size limit. I have edited the php.ini file to the size limit I want it at, and I have also had to add additional lines to the .htaccess file

.htaccess :
php_value upload_max_filesize 20000M
php_value post_max_size 20000M

php.ini:
php_value upload_max_filesize 20000M
php_value post_max_size 20000M

Restarted the web services on the PI, but yet Nextcloud/Owncloud still reads the exact same 1GB - Max Possible 2GB

Any ideas on this one? Funny thing is I would have thought the .htaccess file would already have some instructions on the file size limit by default but it did not I ended up having to add the lines to the file.

I think your syntax is wrong for php.ini (you don't need the php_value), and you are changing post_max_size but I think you want post_max_filesize. I have never changed those values using .htaccess before, I usually change them using php.ini or a file that will get called by it, e.g. on ubuntu and probably debian you can create a separate file where you put your changes. Here's my /etc/php/7.0/apache2/conf.d/99-user.ini:
post_max_filesize = 100M
upload_max_filesize = 100M
Also make sure you have changed apache2's php.ini and not the cli php.ini Sam

I think thats where we have some differences. I am running PHP5 while you are running 7.

With 5 there is no post_max_filesize

However, I removed the php references from the ,htaccess file located in my /media/nextcloud/data directory.

Confirmed changes in the php.ini file is setup correctly , restarted apache2 services, even went as far as rebooting the server and still no change from the 1gb to 4gb

Enter as following
upload_max_filesize = 4096M
post_max_size = 4096M

Still same results - max file upload 1gb

Hi Sam,

I have PostFix installed on my Debian distribution and have configured it following your brilliant tutorials with SquirelMail and Dovecot plus SpamAssassin and Sieve and this is the machine I'm forwarding my port 443 for HTTPS traffic to within my network.

My question is, can I safely deploy OwnCloud following the above steps on the very same machine?
I'm hoping I could then access the web interface of my mailbox with https://mydomain/squirrelmail and the file sharing web interface with https://mydomain/owncloud, whilst using the same SSL certificate.

Or will you recommend dedicating another machine and accessing OwnCloud perhaps thru another port (let's say 4443) instead, which would imply then adding a translation rule on the router to take 4443 as 443 when pointing port 4443 from external to this additional, dedicated machine?

Thank you very much,

Lucian

Depending on how much you are going to use owncloud, i would suggest using another machine... if you have a recent pi then you may not have performance issues, but increasing the wear on the SD card with lots of file syncing is a good way to lose all your data! If you just wanted it for the odd file transfer and caldav, then I wouldn't be too concerned (just make good backups). However, it's perfectly possible technically. If you're going to run both applications on apache, you should read my virtualhosts tutorial, which will explain the kind of changes you will need to make to the apache config to serve the two apps the way you wanted. Note that the virtualhosts tutorial is quite old, so it's now possible to have multiple https domains with their own TLS certs, using server name indication (SNI) - shouldn't matter to you because you only have one domain, but useful to know. Sam

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.