Thursday, October 25, 2012

ownCloud on a Raspberry Pi

This is a project that I have wanted to do for quite a while now. I finally got a free day this previous weekend, so I thought I would dedicate a little time to playing with the Raspberry Pi. The Raspberry Pi, for those not in the know, is a $35 ARM powered computer that is about the size of an Altoids Tin. I only had a day for my project and decided that setting up ownCloud would be interesting. ownCloud is an alternative to many different cloud services, such as file storage (Dropbox, Google Drive, SkyDrive, etc.), calendars (Google Calendar, etc.), music player (Google Music), personal picture viewer (Picasa, flickr,etc), and others. It has quite a few interesting features and is very actively developed.

Setting Up the Raspberry Pi

The Raspberry Pi is surprisingly easy to set up with Raspbian, and I was off and running in no time. I would go through the details, but I followed the Raspberry Pi Wiki article on SD card setup. I was able to use SSH to login after the first boot, so I did not even have to plug it into my TV. I did not do anything special with the configuration of my Pi, but I plan on activating the turbo setting in the firmware, so I can get the processor speed up to 1Ghz.

Setting Up nginx and PHP

In order to run ownCloud, you need a webserver and PHP. Apache can be a bit big for the Pi which only has 256MB of RAM (they now come with 512MB), so I chose to install nginx and PHP-FPM
aptitude install nginx php5-fpm php5-sqlite php5-gd
 Then, create a file in /etc/nginx/sites-available/. I called mine owncloud.vhost:
# redirect http to https.
#server {
#  listen 80;
#  server_name owncloud.example.org;
#  rewrite ^ https://$server_name$request_uri? permanent;  # enforce https
#}

# owncloud (ssl/tls)
server {
  #listen 443 ssl;
  listen 80;
  #ssl_certificate /etc/nginx/certs/server.crt;
  #ssl_certificate_key /etc/nginx/certs/server.key;
  #server_name localhost;
  root /usr/share/nginx/www/owncloud;
  index index.php;
  client_max_body_size 1000M; # set maximum upload size

  # deny direct access
  location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
    deny all;
  }

  # default try order
  location / {
    try_files $uri $uri/ @webdav;
  }

  # owncloud WebDAV
  location @webdav {
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTPS on;
    include fastcgi_params;
  }

  # enable php
  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTPS on;
    include fastcgi_params;
  }
}
I actually got the majority of this file from ownCloud.org. Then create a soft link to /etc/nginx/sites-enabled:

ln -s /etc/nginx/sites-available/owncloud.vhost /etc/nginx/sites-enabled/

Note: I removed the default server in sites-enabled.

I then modified /etc/php5/fpm/php.ini to include the following:

extension=sqlite.so
extension=zip.so
extension=json.so
extension=xmlrpc.so
extension=curl.so
extension=gd.so

Installing ownCloud

I downloaded the gzipped tar of ownCloud 4.5 from ownCloud.org, then decompressed it and copied it to /usr/share/nginx/www/owncloud.

Then,

sudo chown -R www-data:www-data /usr/share/nginx/www/owncloud

You should now be able to start nginx and php-fpm, then using your web browser to go to the IP address of your Pi, and BOOM! ownCloud!

23 comments:

  1. Thanks! I've been messing around with 6 different ways of installing ownCloud with Apache and now, nginx [Apache being too heavy for the RPi]. Your nginx/php install has been the most straight forward and easy.

    ReplyDelete
  2. Probably due to lack of expertise I had a few problems.
    One was, that the ln -s /etc/nginx/sites-available /etc/nginx/sites-enabled creates a link named sites-available in sites-enabled and nginx does not like that. Hence I made links the following way ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled
    Another Problem is, that I do not know how to bring nginx not serve default but owncloud.vhost
    So I moved owncloud.vhost to default.

    You do not have by any chance a clue what I did wrong or where to look for further information?
    I did read http://blog.martinfjordvald.com/2010/07/nginx-primer/ and http://blog.martinfjordvald.com/2010/07/nginx-primer/ but did not succeed in finding my failure.

    Nonetheless, this is a good HowTo, it helped me who never set up such a thing before a lot. And I tried and failed following others. Thank you!

    ReplyDelete
    Replies
    1. Sorry for the confusion.

      I have updated the link command to be more specific. You have to link the individual sites from one directory to the other. Also, I don't have default in my sites-enabled.

      Delete
  3. There are two small mistakes in your owncloud.vhost. Both off the "fastcgi_params HTTPS on;" should be "fastcgi_param HTTPS on;".

    ReplyDelete
  4. Hey, I also just followed your script and everything went quite smooth - so thanks for your work.

    When i enter the raspi's ip into my browser though i get stuck at a page saying "Welcome to ngnix!" Do you have an idea where I might have gone wrong?

    ReplyDelete
    Replies
    1. maybe enter your raspberries ip addres/owncloud ?
      otherwise the browser is going to the index.html in the nginx www folder

      Delete
    2. I think it is just the default-file. Remove it and you should be fine.

      Delete
  5. Hey,
    I also installed owncloud and got it working (4.8) but am not able to get the send link functionality going. How do we need to configure owncloud on the raspi? Tried smtp, php and sendmail but each one give errors.. so the mail is not send.

    ReplyDelete
  6. I do not think that this is raspi-specific. It is probably a better idea to ask in the owncloud-related-forums.

    ReplyDelete
  7. Hey,
    I tryed to follow you're tutorial. But when I start the nginx server I get the following error message:

    nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/default:9

    I updated the /etc/nginx/sites-available/default file with your code above.

    Have you an idea why I get this error?

    ReplyDelete
  8. @Christoph: Did you ever find a fix?

    ReplyDelete
  9. I am very interested in this project, and would be interested in making my ownCloud available anywhere, even outside my LAN using a dns provider like http://dyn.com/dns/

    How exactly would I link the domain I receive from them to the IP address of my owncloud? Thanks for the awesome tutorial, it was perfect in helping me get set up.

    ReplyDelete
    Replies
    1. if your raspberry is directly connected to the modem install the no-ip-client (or the one of a similar service).
      if your raspberry sits behind a router (very likely) your router need to run a client. most routers have one integrated in their firmware.
      look in the configuration website (192.168.1.1 or something similar) and set it up there.
      if you sit behind a router you need to foward the ports you want to be reachable from outside. this should be under a point called "port forwarding" or "NAT".

      if your aim is mainly file sync, then you could have a look at seafile as well, which is easier to install and configure and also a lot faster.

      Delete
  10. First of all, thanks very much for the instructions. I find them very useful!

    I have one problem. Once I login for the first time into Owncloud and after setting the Administrator user and password, Owncloud get stuck with the following order "upgrading filesystem cache".

    The syncronization of files is working, but I cannot access Owncloud via http. I have seen that many people has the same problem but I still could not find a solution.

    Can you please help me! I had to install the version 4.5.13. This version works but is much slower than OC5.

    Thanks!

    ReplyDelete
    Replies
    1. Hi! It's me again!!!!

      Just want to say that I've been testing the version 4.5.13 and it's really fast!!! I'm surprised about the performance of the raspi with ngnix!!!

      Still cannot install the version 5.0.9 (latest now) but the 4.5.13 does also the job!

      Thanks!

      Delete
  11. hi,
    thanks for the how-to, but i also have some problems. nginx is not happy with the config file. it says "unknown directive " listen" in the owncloud.vhost file ?!
    it also says that the configuration file nginx.conf test failed. (one alert that he can't open the error log file due to permission issue and a warning that the "user" directive only makes sense if the master process runs with super user privileges.

    Any help is welcome.

    thanks
    d

    ReplyDelete
  12. Me again. found the problem. Since i used a copy and pasted the conf. lines in a wrong way the config file was defunct. rewrote it and now it works.
    d

    ReplyDelete
  13. Do you know whether it is possible to have Owncloud automatically update when a new release is available, or at least notify me when I need to take action?

    ReplyDelete
  14. Is the owncloud reachable all over the world. So if i'm in a other country i can go to a website to reach my data i have home?

    ReplyDelete
  15. is the cloud reachable over the internet? not only local?

    ReplyDelete
    Replies
    1. just enable port forwarding on your router! (I suggest port 443) and then setup a dynamic dns, such as NO-IP (you can have a nice free plan)

      Delete
  16. Hi, when I acces "mysite-url/owncloud/", the file index.php is downloaded instead of parsed. Is this a configuration error?

    ReplyDelete