Install ownCloud on Raspberry Pi (Moebious) using Nginx

Raspberry Pi logo

You've probably read my post about Install ownCloud on Raspberry Pi (Arch Linux) using Lighttpd. You saw that I had problems with setting up nginx server. Check out a comparison lighttpd vs nginx.

This time I changede distro and try it again. My pick was Moebious. Reason I picked it was the fact that it's minimalistic.

This tutorial has 4 sections:

You can download directly from sourceforge. After you copy it (dd bs=1M if=moebius-*.img of=/dev/sd.device.name bs=1M;sync), open gparted to create a new partition, the rest of the SD (ext4 partition). You can create it from moebious using the command cfdisk /dev/mmcblk0.
You can also do it after the first login, it runs moebious.config. Through that, you can resize the SD card. Unfortunately, it increase to maximum storage. In this tutorial, I used this option.

Remember the default user/pass are
USERNAME: root
PASSWORD: raspi


1. Now boot your Raspberry pi and update everything:

$ apt-get update && apt-get upgrade

2. Make sure you have the following user:

$ groupadd www-data

$ usermod -a -G www-data www-data

3. Make sure you have static IP:

nano /etc/network/interfaces

and change

auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1


4. Install Nginx

apt-get install nginx openssl ssl-cert php5-cli php5-sqlite php5-gd php5-curl php5-common php5-cgi sqlite3 php-pear php-apc curl libapr1 libtool curl libcurl4-openssl-dev php-xml-parser php5 php5-dev php5-gd php5-fpm memcached php5-memcache varnish

5. OPTIONAL, create your SSL certificates for 2 years

$ openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key

# it will ask you to some questions

$ chmod 600 /etc/nginx/cert.pem
$ chmod 600 /etc/nginx/cert.key

6. Configure Ngnix web server

$ nano /etc/nginx/sites-available/default

TIP: to do it faster, first copy the default:
$ cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Delete the default:
$ rm /etc/nginx/sites-available/default

Then create it from scratch:
$ nano /etc/nginx/sites-available/default

The content of my file is (including the secure SSL)

server {
listen 80;
server_name 192.168.1.10;
rewrite ^ https://$server_name$request_uri? permanent; # enforce https
}

server {
listen 443 ssl;
server_name 192.168.1.10;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;
root /var/www/owncloud;
index index.php;
client_max_body_size 1000M; # set maximum upload size
fastcgi_buffers 64 4K;
location ~ ^/owncloud/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}

location / {
try_files $uri $uri/ index.php;
}

location @webdav {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
include fastcgi_params;
}

location ~ ^(?.+?\.php)(?/.*)?$ {
try_files $script_name = 404;
include fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_pass 127.0.0.1:9000;
}
}

Remember, if your static IP is different than mine (192.168.1.10) you should change it with yours.
Also if you don't want to use SSL, delete the lines:
listen 443 ssl;
server_name 192.168.1.10;
ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;
fastcgi_param HTTPS on;

For more information, you should visit ownCloud documentation.

7. Configure max upload limit in php

$ nano /etc/php5/fpm/php.ini

and change the lines

upload_max_filesize = 1000M
post_max_size = 1000M

and also at the end add the following lines:

upload_tmp_dir = /media/data
extension = apc.so
apc.enabled = 1
apc.include_once_override = 0
apc.shm_size = 256

8. Configure PHP

Open the file:
$ nano /etc/php5/fpm/pool.d/www.conf

And change the following line

#from:
listen = /var/run/php5-fpm.sock
#to
listen = 127.0.0.1:9000

Open the file:
$ nano /etc/dphys-swapfile

And change the following line

#from:
CONF_SWAPSIZE=100
#to
CONF_SWAPSIZE=512

9. Restart web server and Php

$ /etc/init.d/php5-fpm restart
$ /etc/init.d/nginx restart


10. Now you can download ownCloud. Go to Download page and choose tar or zip.

A cool tip is to go to server folder (cd /var/www) and write


the extract the file

$ tar -xjf owncloud-6.0.3.tar.bz2

Now you can remove the file (rm owncloud-6.0.3.tar.bz2).

Then you should change the permissions:

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

Create a directory to store data. It's safer to have your data outside your server directory.

$ mkdir /media/data

And change permissions.

$ chown www-data:www-data /media/data

Because I used that directory, I had some problems with WebDAV. I found a solution through forums and more exact at that post.

$ chown -R 775 /media/data

WebDAV issue

11. Now open your browser to http://192.168.1.10 (my raspberry pi static IP, might be different for you). It'll ask you for SSL certificate, if you enabled the secure.

ownCloud Install

Write your admin account and don't forget to hit advanced. As the message says, you better change the default data folder. I did it to /media/data as I set it up before.

12. And now you're in. Enjoy your ownCloud.

ownCloud Personal


EXTRA SETUP

1. My raspberry pi is at home. I have dynamic dns. So I tried to login from outside my house and got the following message:

trusted domain

So I opened the config.php and changed it (I read it at forums):

$ nano /var/www/owncloud/config/config.php

And change the line:

/* List of trusted domains, to prevent host header poisoning ownCloud is only using these Host headers */
'trusted_domains' => array('demo.owncloud.org', 'otherdomain.owncloud.org:8080'),

to

/* List of trusted domains, to prevent host header poisoning ownCloud is only using these Host headers */
'trusted_domains' => array('192.168.1.10', 'XXXX.dlinddns.com:443', 'XXX.dlinddns.com', ),

or

/* List of trusted domains, to prevent host header poisoning ownCloud is only using these Host headers */
'trusted_domains' => array( 0 => '192.168.1.10', 1 => 'XXX.dlinddns.com:443', 2 => 'XXX.dlinddns.com', ),

XXX.dlinddns.com is your dynamic dns address. If you don't use SSL, don't add the XXX.dlinddns.com:443.

2. If you want to use your data to external hard disk (prefer ext4 filesystem), you can add it through ownCloud, but it's better to do it during installation or do the following:

# stop nginx server
$ service nginx stop

# create the directory and mount the disk
$ mkdir /media/USBHDD/
$ mount /dev/sdX1 /medi/USBHDD
# sdX is the usb disk (cat /proc/partitions)

# create the data directory and change the permissions (if you face a WebDAV problem, you should change permissions to chown -R 775)
$ mkdir /media/USBHDD/data
$ chown www-data:www-data /media/USBHDD/data

# move the data directory
$ mv /media/data/ /media/USBHDD/data/

If you didn't change the default data folder, the last command would be
mv /var/www/owncloud/data/ /media/USBHDD/data/

Configure USB directory path in Nginx config.php

$ nano /var/www/owncloud/config/config.php

Change the below line

# from
'datadirectory' => '/media/data'
# to
'datadirectory' => '/media/USBHDD/data'

Start the server:

$ service nginx start

Δεν υπάρχουν σχόλια

Από το Blogger.