Home Cloud: Installing Owncloud 5 with NGINX Web Server on Raspberry PI

Now you can have your own cloud on a Raspberry Pi.

Here is how:

1 Preparing to install with raspi-config

Run Command :

sudo raspi-config

1. expand_rootfs run so we have enough space for packages ownCloud itself and uploads

2. change_locale to ” en_US.UTF-8 ” for the complete system (Otherwise ownCloud complains

that it can lead to errors in file names with special characters)

3. memory_split to ” 16 ” set MB. This is the lowest possible setting. The GPU gets 16MB so.

4. overclock on ” medium “4 ” Finish ” and then reboot with the question of the ” Yes ” answer.

2 Update package lists

Run Commands :

sudo apt-get update
sudo apt-get upgrade

3 Create user

Run Commands :

sudo groupadd www-data
sudo usermod -a -G www-data www-data

4 Installing the packages

Run Command :

sudo 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 Create SSL Certificate (valid for 1 year)

Run Commands :

sudo openssl req $@ -new -x509 -days 365 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key
sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key

6 Configure nginx web server

Run Command :

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

Here you will delete the ENTIRE content and insert the content below.

Make sure that their IP address ” 192.168.XXX.XXX replaced “with your Raspberry Pi. You can find your local ip address with “ifconfig” command. Depending on how you have the Pi connected, you can extract the devices ” eth “or”wlan “your IP address from the following line:” inet addr:

192.168.0.109 Bcast: 192.168.0.255 Mask: 255.255.255.0 ".
server {
 listen 80;
 server_name 192.168.XXX.XXX;
 rewrite ^ https://$server_name$request_uri?permanent; # enforce https

server {
 listen 443 ssl;
 server_name 192.168.XXX.XXX;
 ssl_certificate /etc/nginx/cert.pem;
 ssl_certificate_key /etc/nginx/cert.key;
 root /var/www;
 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 ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ {
     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;

Then we set the values in the file “upload_max_filesize” and “post_max_size” to 1000M in PHP.ini file.
Run Command:

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

Little tip: The php.ini is a very long file. So it makes sense to search for the two terms

(“upload_max_filesize” and “post_max_size”) with “CTRL + W” to search. So you avoid looking for your time.

upload_max_filesize = 1000M
post_max_size = 1000M

At the end of the file, we’ll add another following:

upload_tmp_dir = /srv/http/owncloud/data
extension = apc.so
apc.enabled = 1
apc.include_once_override = 0
apc.shm_size = 256

Next, we create the folder with the associated rights

Run Command:

sudo mkdir -p /srv/http/owncloud/data
sudo chown www-data:www-data/srv/http/owncloud/data

7 Configure PHP

Run Command:

sudo nano /etc/php5/fpm/pool.d/www.conf

Here you can change the following line from:

listen = /var/run/php5-fpm.sock

to

listen = 127.0.0.1:9000

Run Command:

sudo nano /etc/dphys-swapfile

Here you can change the following line from:

CONF_SWAPSIZE=100
CONF_SWAPSIZE=512

8 Restart web server and PHP

Run Command:

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

9 Install ownCloud

Finally, we install ownCloud. Work the following commands one after.

Among other things we create here the directory “/ var / www / ownCloud”, download and unzip ownCloud, move it to the correct directory, assign the required rights and delete the previously downloaded archive. latest version note. In this tutorial, the version daily was used

Run Command:

sudo mkdir -p /var/www/owncloud
sudo wget http://download.owncloud.org/community/owncloud-daily-master.tar.bz2
sudo tar xvf owncloud-daily-master.tar.bz2
sudo mv owncloud/ /var/www/
sudo chown -R www-data:www-data /var/www
sudo rm -rf owncloud owncloud-daily-master.tar.bz2

Now you can access the server at the ip address of the Raspberry PI. For me it is in the case of

“https://192.x.x.x/owncloud”

Finally you must now set administrator password and user name .

 

The installation is now complete

Proceed if you want to use an external HDD to as the OwnCloud Data store

instead of your SD Card

10 Mount a USB HDD to your Raspberry Pi

Connect your USB HDD to Raspberry Pi (it should be external powered . Raspberry Pi cannot supply

enough power to run the USB HDD)

Run Command:

tail -f /var/log/messages

you will see which identifier is set for the external drive . In the below case its sda1

Make a directory where you will mount the USB HDD and Mount the HDD

Run Command:

sudo apt-get install ntfs-3g
sudo mkdir /media/USBHDD (where USBHDD can be anything you like)
sudo mount -t ntfs-3g /dev/sda1 /media/USBHDD

you should be able to see the contents of USB HDD now

Run Command:

sudo ls /media/USBHDD

11 Use USB HDD for Owncloud

First we create a directory in USB HDD to hold the owncloud data folder

Run Commands:

sudo service nginx stop
sudo mkdir /media/USBHDD/OwnCloud5
sudo chown www-data:www-data /media/USBHDD/OwnCloud5
sudo mv /var/www/owncloud/data/ /media/USBHDD/OwnCloud5/

Open Config.php and change the directory to USB Directory

Run Command:

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

Change the below line

From:

'datadirectory' => '/var/www/owncloud/data'

to:

'datadirectory' => '/media/USBHDD/OwnCloud5/data'

Run Command:

sudo service nginx start

Proceed if your external HDD is using NTFS Filesystem.

Fix for error :

Data directory /media/USBHDD/OwnCloud5/data’) is readable for other users. Please change the permissions to 0770 so that the directory cannot be listed by other users.

12 Remove the check for Directory permissions

Run Command:

sudo nano /var/www/owncloud/lib/util.php

Change the below function in the file

/**
 * Check for correct file permissions of data directory* @return array arrays with error messages and hints
*/
public static function checkDataDirectoryPermissions($dataDirectory) {
$errors = array();
if (stristr(PHP_OS, 'WIN')) {
//TODO: permissions checks for windows hosts
} else {
$permissionsModHint = 'Please change the
permissions to 0770 so that the director
$
.' cannot be listed by other users.';
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($prems, -1) != '0') {
OC_Helper::chmodr($dataDirectory, 0770);
clearstatcache();
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($prems, 2, 1) != '0') {
$errors[] = array('error' => 'Data directory
('.$dataDirectory.')$
'hint' => $permissionsModHint);
}
}
}
return $errors;
}

To: (basically commenting out the section which checks for the directory permissions.)

/**
* Check for correct file permissions of data directory
* @return array arrays with error messages and hints
*/
public static function checkDataDirectoryPermissions($dataDirectory) {
$errors = array();
if (stristr(PHP_OS, 'WIN')) {
//TODO: permissions checks for windows hosts
}
/*
else {
$permissionsModHint = 'Please change the permissions to 0770 so that
the director$
.' cannot be listed by other users.';
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($prems, -1) != '0') {
OC_Helper::chmodr($dataDirectory, 0770);
clearstatcache();
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($prems, 2, 1) != '0') {
$errors[] = array('error' => 'Data directory
('.$dataDirectory.')$
'hint' => $permissionsModHint);
}
}
}*/
return $errors;
}

Proceed if your had an existing OwnCloud Instance and want to move data to

the new instance. Generally used when upgrading newer version of Owncloud.

13 Copy Old OwnCloud data to the new instance

Run Command:

sudo service nginx stop
sudo cd /media/USBHDD/OwnCloud5/data/
sudo sqlite3 owncloud.db (opens owncloud database’ )
sqlite>.tables (Gives you list of tables in owncloud database. check the tables to make sure files cache table is there . It could be ‘oc_fscache’ or ‘oc_filescache’ )
sqlite>delete from oc_filescache; (or delete from oc_fscache )
sudo mv /media/USBHDD/<old Owncloud folder>/data/<username>/files/media/USBHDD/OwnCloud5/data/<username>/files (moves files from old )
sudo service nginx start

Modified from original work of: Gary Tahl. Thank you.

More reading on creating SSL certificate: https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04/

 

[post_view]

(Visited 791 times, 1 visits today)