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. 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). 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. 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. 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
Hi and thanks for the highly
Hi and thanks for the highly instructive tutorial.
I'm running OC 8.0.4 on my RPI and would like to jump to 8.1. Do you know if 8.1 runs on the RPI and if so, is there a specific process to follow for the update?
I've heard it runs fine, but haven't tried it myself
Website
How do I link it to my domain name?
Repo's
Why don't you use the software repos available from ownCloud? Just wondering because it would be easier than downloading and unpacking the file from their website. It would also always be up to date.
Thanks anyway, Matt
Repo wasn't available at the time
Hello Sam
Hi I'm still a bit of a noob and would like to know how to do the things you said in this great tutorial but I'm not using apache2 I'm using "nginx" so can I do the things you said like moving my owncloud so I can access it from Http/mydomain.com and how can I use PHP cache?
And one last questionings
How do I make my own cloud accessible from wan access at the moment if I share a file it gives me my 192...... address so how would you access the share from where ever you are lets say.
Oh and one more thing is there a way to make owncloud use btsync witch uses P2P protocol to send files as its own service when downloading a file from the web interface ?
Never used nginx
Errors on OC 8.2
First of all Great guide.
I have update to 8.2 and i found my self whit some problems .
I can not upload files bigger that 512 MB, i have look for the answer and what i have change is in the php.ini file the max
sudo nano /etc/php5/apache2/php.ini
upload_max_filesize = 2G
post_max_size = 2G.
is not working
and i also getting some php errors
Your PHP version (5.4.45-0+deb7u2) is no longer supported by PHP. We encourage you to upgrade your PHP version to take advantage of performance and security updates provided by PHP..
Thank you
Looks like you're using
Great guide but beed some expert help
Hi Sam
First off, thanks for the walk through, good walkthroug for a newbie like myself. I followed your guide from scratch but have a question i would like to be able to brows the /data folder on samba or from windows network rather but when i make the file permissions owner to Apache (www-data) samba fails to open that folder so how do i add PI, SAMBA, WWW-DATA and a few other users to one owner that can access www-data folder?
samba questions
mogo samba
Hello Sam
I would like to be able to do basic file operations on the owncloud data folder.
What command would i need to run after adding a file to the /data directory and where?? I've noticed some way of making own cloud do a cron job from the admin page. is that the same as a normal cron job ?
I have issued the command but now what file permissions can i put the /data folder in as it still only lets me view it as root, If It has to be www-data then can i change the "change content" from only owner to everyone or will that break it?
I still don't really
ls -l
), so you should be able to view the files already (maybe reboot to make sure the changes take effect, normally logging out and back in is enough to do it but I'm not sure how that works with samba). If you want the www-data group to be able to read the files, all of the parent dirrctories need the execute bit set, and the files need the read bit, e.g. for read only 750 dirs and 640 files, or for read-write 770 dirs and 660 files. The occ command is inside the owncloud folder (not in $PATH) and It's a php script so you must run it like this:sudo -u www-data php /var/www/owncloud/occ files:scan
Adjust the path as necessary. I really don't recommend doing that. More info on occ command. SamMore VHosts help
ok so I am trying to look at how to change the /etc/apache2/sites-available/default file to add your ANTI PROXY SPAM thing from your other guide https://samhobbs.co.uk/2014/01/multiple-websites-and-subdomains-with-ss… but my VHosts file looks different its the default from ownclud and apche2 so i'm not sure what to do as my external ip is not static so do i need to register with some dns thing, is that correct to be find-able like //samhobbs.co.uk is?
also after opening port 80 on my router or just dmz ing the RPI ip address i want to be able to type http:whatever.com and it load the currently installed /owncloud/index.php and that is im not sure as my vhost file has no entry for ownloud it just has /var/www but if i go to my ip address it just tells me it works
This is my v host file that works from /owncloud/index.php
ServerAdmin webmaster@localhost
DocumentRoot /var/www
Options FollowSymLinks
AllowOverride All
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
so this is my idea of the edit i was asking about will this work or will it break it ?
ServerName default.only
Order allow,deny
Deny from all
ErrorLog ${APACHE_LOG_DIR}/spam/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/spam/access.log combined
ServerAdmin ##Would a gmail address work here if so how woild it know the login details to send the messages??
ServerName ##would http:whatever.com:80 work? is it that simple??
ServerAlias whatever.com
DocumentRoot /var/www ## do i add /owncoud here or
Options FollowSymLinks
AllowOverride All
### here??
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Missing file
Hi. I am trying to install owncloud from your tutorial.
I am using Jessie Raspbian I am in this step
sudo nano /etc/apache2/sites-enabled/000-default.
But there's no 000-default file there's a 000-default.conf
What can I do?
Thanks
Hi,
Sam this is the output of the
Sam this is the output of the file, can I still use it
Thanks
pi@raspberrypi /etc/apache2/sites-enabled $ cat 000-default.conf
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
pi@raspberrypi /etc/apache2/sites-enabled $
yes, but read the virtualhost tutorial
No, believe me I whant to do
No, believe me I whant to do this I have learn a lot from tutorial but I am still a noob so I have to ask the question I know some will answer. And if you don't mine when i get it working can I post my script here. I don't think I am the only one whit this situation.
Thanks, sam
Admin button under user name takes me to a blank page
Hi Sam,
Great page, and tutorial, I've had a problem when I go to the drop down menu and select 'admin' to 'enforce HTTPS' , it takes me to a blank page. Any suggestions greatly appreciated.
Simon
Never seen that before!
Blank admin page
The page is not loading anything. it even states in the top bar 'blank page'.
I've reinstalled a number of times but still the same problem.
Simon.
What's in the log?
/var/log/apache2/ssl_access.log
unless you changed it)? You can watch it in real time with: SamOwncloud on webserver and database server
Hi Sam,
Another great tutorial.
In my setup I have a pi running as a webserver and a mail server (as per your email server guide) and a second pi which contains more dynamic files such as the mysql server and media files.
Is there a way to set up owncloud so that it will run on my existing apache2 webserver but use the 'back end' server to store files and run its database?
Though you can connect to the database using standard mysql sockets etc. and I'm guessing somewhere in the owncloud config there's a way of setting that, how can I point owncloud at a files and folders on a disk which is on a separate pi?
fstab
Failure when restarting apache2 service
Hi Sam,
Me again...
When I tried to restart the apache2 service after enabling with ' sudo a2usermod rewrite', I get an error/failure. This also happened this morning after the a2enmod rewrite as well as the a2enmod headers part, so I restarted the whole process from scratch including formatting my micro sd card, etc.
Here is the shell and what I see/get:
admin@pi-box:~ $ sudo nano /etc/apache2/sites-enabled/000-default.conf
admin@pi-box:~ $ cd /var/www/
admin@pi-box:/var/www $ ls -a
. .. html owncloud
admin@pi-box:/var/www $ cd owncloud
admin@pi-box:/var/www/owncloud $ ls -a
. config db_structure.xml l10n public.php status.php
.. console.php .htaccess lib remote.php .tag
3rdparty COPYING-AGPL index.html occ resources themes
apps core index.php ocs robots.txt .user.ini
AUTHORS cron.php indie.json ocs-provider settings version.php
admin@pi-box:/var/www/owncloud $ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
admin@pi-box:/var/www/owncloud $ sudo service apache2 restart
Job for apache2.service failed. See 'systemctl status apache2.service' and 'journalctl -xn' for details.
admin@pi-box:/var/www/owncloud $ systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Active: failed (Result: exit-code) since Thu 2016-02-18 14:50:35 UTC; 1min 5s ago
Process: 9704 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
Process: 9732 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)
admin@pi-box:/var/www/owncloud $ journalctl -xn
No journal files were found.
Any ideas?
Regards,
Jo
logs
/var/log/apache2/error.log
. I expect there's a syntax error in your config file, but we won't know until you find and read the log. SamMaybe in the vhost?
Hi Sam,
Here's the output, can't make much sense of it...something in the vhost I think regarding the domain name or path?
admin@pi-box:/var/www/owncloud $ sudo systemctl status apache2.service
[sudo] password for admin:
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Active: failed (Result: exit-code) since Thu 2016-02-18 15:01:32 UTC; 57min ago
Feb 18 15:01:32 pi-box apache2[9883]: The apache2 configtest failed. ... (warning).
Feb 18 15:01:32 pi-box apache2[9883]: Output of config test was:
Feb 18 15:01:32 pi-box apache2[9883]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Feb 18 15:01:32 pi-box apache2[9883]: (2)No such file or directory: AH02291: Cannot access directory '/var/log/apache2/pi-box/' for error log of vhost defined at /etc/apache2/sites-enabled/000-default.conf:1
Feb 18 15:01:32 pi-box apache2[9883]: AH00014: Configuration check failed
Feb 18 15:01:32 pi-box apache2[9883]: Action 'configtest' failed.
Feb 18 15:01:32 pi-box apache2[9883]: The Apache error log may have more information.
Feb 18 15:01:32 pi-box systemd[1]: apache2.service: control process exited, code=exited status=1
Feb 18 15:01:32 pi-box systemd[1]: Failed to start LSB: Apache2 web server.
Feb 18 15:01:32 pi-box systemd[1]: Unit apache2.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.
admin@pi-box:/var/www/owncloud $ sudo journalctl -xn
-- Logs begin at Thu 2016-02-18 14:20:39 UTC, end at Thu 2016-02-18 15:59:48 UTC. --
Feb 18 15:57:35 pi-box kernel: hid-generic 0003:04F3:0103.0004: input,hidraw1: USB HID v1.10 Keyboard [HID 04f3:0103] on usb-3f980000.usb-1.4/input0
Feb 18 15:57:35 pi-box kernel: input: HID 04f3:0103 as /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.1/0003:04F3:0103.0005/input/input4
Feb 18 15:57:35 pi-box kernel: hid-generic 0003:04F3:0103.0005: input,hidraw2: USB HID v1.10 Device [HID 04f3:0103] on usb-3f980000.usb-1.4/input1
Feb 18 15:57:35 pi-box systemd-udevd[12061]: failed to execute '/lib/udev/mtp-probe' 'mtp-probe /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4 1 6': No such file or directory
Feb 18 15:57:55 pi-box dhcpcd[447]: eth0: fe80::1 router available
Feb 18 15:58:34 pi-box sudo[12123]: admin : TTY=pts/0 ; PWD=/var/www/owncloud ; USER=root ; COMMAND=/bin/systemctl status apache2.service
Feb 18 15:58:34 pi-box sudo[12123]: pam_unix(sudo:session): session opened for user root by (uid=0)
Feb 18 15:58:34 pi-box sudo[12123]: pam_unix(sudo:session): session closed for user root
Feb 18 15:59:48 pi-box sudo[12141]: admin : TTY=pts/0 ; PWD=/var/www/owncloud ; USER=root ; COMMAND=/bin/journalctl -xn
Feb 18 15:59:48 pi-box sudo[12141]: pam_unix(sudo:session): session opened for user root by (uid=0)
admin@pi-box:/var/www/owncloud $
Here's my 000-default.conf file details:
ServerAdmin webmaster@pi-box.co.uk
ServerName www.pi-box.co.uk:80
ServerAlias pi-box.co.uk
DocumentRoot /var/www
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
ErrorLog ${APACHE_LOG_DIR}/pi-box/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/pi-box/access.log combined
Apologies for all the questions all the time...I'm learning a lot, just a bit slow right now.
Thanks for all the support.
Regards,
Jo
log directory doesn't exist
/var/log/apache2/pi-box
and restart apache2. BTW, you can use the-u
flag with journalctl to display output from just one service, e.g: (most of the output you pasted was from other services!) SamCreated pi-box folder - SUCCESS!
Hi Sam,
As always, thanks. I successfully restarted the apache2 service.
Just another quick one:
Testing the installation with www.pi-box.co.uk/owncloud gives an error, but 192.168.1.100/owncloud gives the installation wizard. Is this ok or is there something I missed earlier?
I tried connecting from outside my LAN, but also an error. Do I ned to do anything with my router (port forwarding?) as I had to do with my email server?
Regards,
Jo
Add new comment