Tag Archives: ownCloud

How To Install ownCloud on Raspberry Pi

OwnCloud is a clever self-hosted alternative to Dropbox and its ilk that provides the same services without the expense of subscriptions or the likelihood that government or marketer’s eyes are prying into your documents. For most consumers, this might be considered more trouble than it’s worth, but rolling your own cloud server under your control is essential to keeping the free and open web–well, free and open. The Raspberry Pi’s $35 price tag makes it especially handsome for a low-cost cloud server using free and open source software. In addition to being an excellent option for cloud storage–especially for those of us with terabytes of material to store–ownCloud is going to provide us with easy online access to photo storage for Project Spoofy. We’ll just point the slideshow application to the ownCloud folders for simplicity later! For now, let’s get started with how to install ownCloud on Raspberry Pi.

How to install ownCloud on Raspberry Pi

First, we need to add the ownCloud repository to the Pi’s sources list. At the command prompt, type sudo nano /etc/apt/sources.list.d/owncloud.list and hit return. This will create a new text file in the Nano text editor. On the first line of the text file, type deb http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_6.0/ /

Type CTRL+x to exit Nano, then Y and return to save.

Now we need to add the repository key so we can access the repository. Download the key by typing wget http://download.opensuse.org/repositories/isv:ownCloud:community/Debian_6.0/Release.key at the command prompt. Once the key is downloaded, add it to the repository by invoking sudo apt-key add - < Release.key

After adding the key, update the repositories by typing sudo apt-get update and return.

Now, we can install ownCloud by typing sudo apt-get install owncloud and return. Press Y for any questions the system asks you, and sit back while ownCloud and MySQL are installed. At some point, MySQL will prompt for a  root password. Choose something interesting and note it for later.

Setting Up ownCloud’s Directory Permissions

Once everything is finished installing, it’s time to set up ownCloud’s directory permissions. First thing, we need to make sure that HTTP has ownership of the ownCloud directory. To do this, make www-data the owner of owncloud by invoking the following command:

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

Now that HTTP has ownership, we need to adjust the permissions for maximum security. ownCloud has actually provided a script to set all the permissions automatically. Copy the following, paste into a shell script (*.sh file, such as “ocperms.sh” for example) using Nano, and save to a convenient location on the Pi.

#!/bin/bash
ocpath='/var/www/owncloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'
printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750
printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chmod +x ${ocpath}/occ
printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
 then
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
 then
  chmod 0644 ${ocpath}/data/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

Now, make the script executable by typing chmod u+x /ocperms.sh and enter, then execute it by typing ocperms.sh

Set up MySQL

One last step before we run the installation wizard: we must create a MySQL database. When we installed ownCloud, MySQL was installed by default, so we have that going already. Now, just log into the MariaDB client as root by typing mysql -u root -p and return at the command prompt. MySQL will ask for the root password you set earlier then display a new command prompt.

You’ll need to choose a database name, user, and password for ownCloud. In this example, I’ll be using some generics (dbname, dbuser, dbpw), but feel free to make it your own.

Type the following commands at the MySQL prompt (case-sensitive):

CREATE DATABASE dbname;

GRANT ALL ON dbname.* TO dbuser@localhost IDENTIFIED BY 'dbpw';
Then, exit the client by typing quit and return.

Lastly, reboot the Raspberry Pi to make sure all the changes are updated.

Run the ownCloud Installation Wizard

We’re finally ready to start running ownCloud! From the Raspberry Pi command prompt, type startx and return to enter the GUI so we can launch a web browser. Using the browser, navigate to http://localhost/owncloud. If everything was set up correctly, you should see the following screen:

Install Owncloud on Raspberry Pi

Fill in the blanks with whatever you would like your ownCloud administrator account credentials to be, click the “Storage & database” drop-down and verify that the storage directory is correct and that MySQL is selected. Also enter the MySQL account credentials that you set up in the last section. Click the “Finish setup” button and you should be dropped into ownCloud’s web interface.

It is possible (if you’re accessing ownCloud from a different computer using the Raspberry Pi’s IP address) that you may run across a “Trusted Domains” error. If that happens, follow the instructions on the screen. If you are unable to automatically add your domain to the whitelist, you will need to do so manually by editing the config.php file in the owncloud directory.

Install Owncloud on Raspberry Pi

Open a terminal window and type sudo nano /var/www/owncloud/config/config.php to edit the configuration file. Look for the section that looks like the following:

'trusted_domains' =>
array (
0 => 'localhost',
),

and change it to look like

'trusted_domains' =>
array (
0 => 'localhost', 'IP OR URL ADDRESS HERE',
),

where you simply add the IP or URL addresses that you wish to use to access ownCloud. This will come in handy later when we set up remote access. Save the config.php file and reload ownCloud. You should be now able to access the application without a problem!

For more information, please see the ownCloud documentation as well as detailed instructions here and here. I’ve done my best to parse all the pertinent instructions from these sources into something simpler for even the novice to be able to follow.