[How-To] ownCloud using NGINX, PHP-FPM, and MySQL

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949

neto_hugo

Explorer
Joined
Mar 6, 2012
Messages
87
Guys I have the OC installed on a 1TB HDD and It's running fine.
I bought a new HDD, now 4TB, and would like to transfer the OC for it.

What is the best way to do this? Snapshot? Or is it better to install from scratch?

In fact this new HD is only for new files and those that already exist on 1TB HDD, the jail is on another HD along with other plugins. So I think I could only change the storage location, right?

Thanks for your help!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Guys I have the OC installed on a 1TB HDD and It's running fine.
I bought a new HDD, now 4TB, and would like to transfer the OC for it.

What is the best way to do this? Snapshot? Or is it better to install from scratch?

In fact this new HD is only for new files and those that already exist on 1TB HDD, the jail is on another HD along with other plugins. So I think I could only change the storage location, right?

Thanks for your help!
Assuming the zpool of your 1TB is tank, and the zpool on your 4TB is new..
  1. stop your owncloud jail from the jails tab
  2. create a new dataset new/files, snapshot+zfs send works but for this simple of a job I'd personally use "cp -R /mnt/tank/files /mnt/new/files"
  3. chown -R www:www /mnt/new/files
  4. For the owncloud jail change the Storage Source to /mnt/new/files
  5. start your owncloud jail
Once everything is working setup snapshots on new/files and destroy tank/files

####

This doesn't migrate tank/db, but that can be done in a similar fashion (but the owners should be UID/GID 88). I sort of regret adding the tank/db dataset to the guide, because while it does theoretically increases performance, it makes things more complicated.
 

Nick Longo

Dabbler
Joined
Jan 30, 2015
Messages
17
well done on the write up. I used it configure Owncloud but pointing to another mysql instances in another jail ( have other apps using the one DBA) but the steps where clear. A couple issues but nothing major. It did take me a bit because I was trying to access Owncloud at the root of the web server and I couldn't figure out the issue at first then I re-read your instructions and noted it was at URL/owncloud so I just moved it and updated nginx config.

Thank you!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
well done on the write up. I used it configure Owncloud but pointing to another mysql instances in another jail ( have other apps using the one DBA) but the steps where clear. A couple issues but nothing major. It did take me a bit because I was trying to access Owncloud at the root of the web server and I couldn't figure out the issue at first then I re-read your instructions and noted it was at URL/owncloud so I just moved it and updated nginx config.

Thank you!
welcome, glad you got it configured how you want it.
 

Dan Sherman

Cadet
Joined
Apr 28, 2014
Messages
5
Joshua, thanks for writing this up!

Owncloud is set up to use smb to connect to the datastore on FreeNAS, so we can use cifs/smb shares in the office and owncloud sync on the road.
It's working really well for me, with one little exception: I have pages of these in FreeNAS's log. Is it just running its initial index, or should I worry about these?

Code:
Feb 10 14:42:36 SPVault smbd[39533]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:58488) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39535]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:14860) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39537]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:20382) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39539]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:55669) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39541]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:45323) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39543]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:43790) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39545]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:51078) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39548]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:45830) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39550]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:10126) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39552]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:41825) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39554]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:55418) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39556]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:35114) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39558]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:12815) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39560]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:38229) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39562]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:24500) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39564]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:48505) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39566]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:12331) closed connection to service data
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Joshua, thanks for writing this up!

Owncloud is set up to use smb to connect to the datastore on FreeNAS, so we can use cifs/smb shares in the office and owncloud sync on the road.
It's working really well for me, with one little exception: I have pages of these in FreeNAS's log. Is it just running its initial index, or should I worry about these?

Code:
Feb 10 14:42:36 SPVault smbd[39533]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:58488) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39535]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:14860) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39537]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:20382) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39539]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:55669) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39541]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:45323) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39543]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:43790) closed connection to service data
Feb 10 14:42:36 SPVault smbd[39545]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:51078) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39548]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:45830) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39550]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:10126) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39552]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:41825) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39554]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:55418) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39556]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:35114) closed connection to service data
Feb 10 14:42:37 SPVault smbd[39558]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:12815) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39560]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:38229) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39562]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:24500) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39564]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:48505) closed connection to service data
Feb 10 14:42:38 SPVault smbd[39566]:   STATUS=daemon 'smbd' finished starting up and ready to serve connectionsowncloud (ipv4:10.0.10.4:12331) closed connection to service data
I have no idea, don't use SMB. This could probably be better answered in owncloud forum.
 

acook8103

Dabbler
Joined
Mar 6, 2012
Messages
12
Anyone had any luck upgrading to ownCloud 8?

I was able to upgrade just fine, and syncing seems to be working perfectly, but I can't download anything via the web interface.

Here's a sample line from /var/log/nginx-error.log (prettified):
Code:
2015/02/10 15:36:54 [error] 45820#0: 
*172 open() "/usr/local/www/mnt/clouddata/acook8103/files//Photo-2014-09-19-10-58-07_0426.JPG" 
failed (2: No such file or directory), 
client: 10.101.1.174, 
server: , 
request: "GET /owncloud/index.php/apps/files/ajax/download.php?dir=%2F&files=Photo-2014-09-19-10-58-07_0426.JPG HTTP/1.1", 
upstream: "fastcgi://unix:/var/run/php-fpm.sock", 
host: "cloud.example.com", 
referrer: "https://cloud.example.com/owncloud/index.php/apps/files/"


It's pretty obviously the 'usr/local/www/mnt/clouddata' path that's the problem, but I'm not sure if it's some non-standard configs in this FreeNAS setup that someone else has figured out already, or if I need to take it to the ownCloud Forums.

The nginx config is a copy from the OP with path tweaks.
Code:
worker_processes 2;

events {
    worker_connections  1024;
}

http {
    include      mime.types;
    default_type  application/octet-stream;
    sendfile        off;
    keepalive_timeout  65;
    gzip off;

    server {
        root /usr/local/www;
        location = /robots.txt {
                allow all;
                access_log off;
                log_not_found off;
        }

        location = /favicon.ico {
                access_log off;
                log_not_found off;
        }

        location ^~ /owncloud {
            index index.php;
            try_files $uri $uri/ /owncloud/index.php$is_args$args;
            client_max_body_size 1024M;
            location ~ ^/owncloud/(?:\.|data|config|db_structure\.xml|README) {
                deny all;
            }
            location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                include fastcgi_params;
                fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
            }
            location ~* \.(?:jpg|gif|ico|png|css|js|svg)$ {
                expires 30d; add_header Cache-Control public;
            }
            location ^~ /owncloud/data {
                internal;
                alias /mnt/clouddata;
            }
        }
    }
}

PHP:
<?php
$CONFIG = array (
  'instanceid' => 'id',
  'passwordsalt' => 'salty',
  'secret' => 'giberish',
  'trusted_domains' =>
  array (
    0 => '10.101.1.167',
    1 => 'cloud.example.com',
  ),
  'datadirectory' => '/mnt/clouddata',
  'overwrite.cli.url' => 'http://10.101.1.167/owncloud',
  'dbtype' => 'mysql',
  'version' => '8.0.0.7',
  'dbname' => 'owncloud',
  'dbhost' => 'localhost:/tmp/mysql.sock',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'ocuser',
  'dbpassword' => 'ocpass',
  'installed' => true,
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => 'smtp.example.com',
  'mail_smtpport' => '25',
  'mail_from_address' => 'donotreply',
  'mail_domain' => 'example.com',
  'overwritewebroot' => '/owncloud',
  'forcessl' => true,
  'maintenance' => false,
  'theme' => '',
  "appstoreenabled" => true,
);
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
your nginx config looks good to me. what's weird is the alias seems to be appended to the root location when determining the path.
maybe OC8 changed something slightly? I'll try investigating.
 

derekzchu

Dabbler
Joined
Dec 5, 2014
Messages
23
yeah it could proxy to anything it can connect to. yes you wouldn't be able to access anything anymore if nginx/the jail crashed. nginx has never crashed (and I've been using it for years, Facebook even uses it for SSL termination). but I have had jails lose their IP address, but only when im changing things.

hey Joshua,

I'm very interested in learning how to reverse proxy. For my setup, I have a few different programs (couchpotato, sonarr, plex, owncloud(SSL), sabnzbd, openvpn) with different IP addresses/ports. Would it be possible to setup the reverse proxy such that I can just use a ddns such as foo.ddns.bar/<program_name> and it'll forward the request to the correct program?

you mentioned you have nginx reverse proxy setup on your NAS. would it be possible to see the relevant parts of your nginx file? thanks.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
hey Joshua,

I'm very interested in learning how to reverse proxy. For my setup, I have a few different programs (couchpotato, sonarr, plex, owncloud(SSL), sabnzbd, openvpn) with different IP addresses/ports. Would it be possible to setup the reverse proxy such that I can just use a ddns such as foo.ddns.bar/<program_name> and it'll forward the request to the correct program?

you mentioned you have nginx reverse proxy setup on your NAS. would it be possible to see the relevant parts of your nginx file? thanks.
You would need to setup each program to use a specific webroot, then setup your nginx.conf with a server block similar to the below. If you have owncloud setup like this guide, just add entrys for the other services to other locations (and have it proxy to the respective jail IPs, not 127.0.0.1 which would only work for stuff in the owncloud jail)

Code:
  server {
    location / {
      return 301 $scheme://$host/maraschino/;
      location ^~ /maraschino {
          proxy_pass http://127.0.0.1:7000;
      }
      location ^~ /sabnzbd {
        proxy_pass http://127.0.0.1:8080;
      }
      location ^~ /transmission {
        proxy_pass http://127.0.0.1:9091;
      }
      location ^~ /sickrage {
        proxy_pass http://127.0.0.1:8081;
      }
      location ^~ /couchpotato {
        proxy_pass http://127.0.0.1:5050;
      }
    }
  }


Yes, what you are asking is possible. I personally also added a password to my NGINX config for the above plugins and don't have them password protected individually.
 

Chakalov

Explorer
Joined
Feb 9, 2015
Messages
53
I just wanted to say how grateful I am to Joshua for writing this perfect tutorial! It all worked just like a charm from A to Z and I was able to deliver a pretty good service to 5 clients working together on daily basis with 15GB of 30k relatively small files (word, excel, pdf, jpeg etc.) without having any problem at all and by doing so ditching Dropbox services for good. Full sync completes in just under 2 hours which I think is amazingly fast!

My Fail2Ban is set and running after just a minute thanks to the flawless tutorial of Rickle so I could say the only thing missing is securing my connection via SSL and I'm good to go.

Thank you guys for all your effort! I truly appreciate your work!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I just wanted to say how grateful I am to Joshua for writing this perfect tutorial! It all worked just like a charm from A to Z and I was able to deliver a pretty good service to 5 clients working together on daily basis with 15GB of 30k relatively small files (word, excel, pdf, jpeg etc.) without having any problem at all and by doing so ditching Dropbox services for good. Full sync completes in just under 2 hours which I think is amazingly fast!

My Fail2Ban is set and running after just a minute thanks to the flawless tutorial of Rickle so I could say the only thing missing is securing my connection via SSL and I'm good to go.

Thank you guys for all your effort! I truly appreciate your work!
Glad it worked for you. Do realize upgrading this setup to OC8 (which will be available from Admin > Upgrade in the coming days) won't work because they changed the way x-accel works. Please check the NGINX config, I disabled it for now till this is fixed.
 

Chakalov

Explorer
Joined
Feb 9, 2015
Messages
53
Any idea what's going wrong?

Qr3uKdp.png


I can't download anything via the web browser, only when I use the ownCloud client. I'm pretty sure there were no errors like this before.... hummm...

Thanks in advance!

p.s.
the latest error says
Fatal remote An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
 
Last edited:

Chakalov

Explorer
Joined
Feb 9, 2015
Messages
53
I've messed up with the nginx.conf didn't I?

Code:
worker_processes 2;



events {
    worker_connections  1024;
}


http {
    include      mime.types;
    default_type  application/octet-stream;
    sendfile        off;
    keepalive_timeout  65;
    gzip off;

    server {
        root /usr/local/www;
        location = /robots.txt { allow all; access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }
        location ^~ /owncloud {
            index index.php;
            try_files $uri $uri/ /owncloud/index.php$is_args$args;
            client_max_body_size 512M;
            location ~ ^/owncloud/(?:\.|data|config|db_structure\.xml|README) {
                deny all;
            }
            location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                include fastcgi_params;
                fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
            }
            location ~* \.(?:jpg|gif|ico|png|css|js|svg)$ {
                expires 30d; add_header Cache-Control public;
            }
            location ^~ /owncloud/data {
                internal;
                alias /mnt/files;
            }
        }
    }
}


My ownCloud location is at /mnt/zdrive/ownCloud if that matters.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I've messed up with the nginx.conf didn't I?

Code:
worker_processes 2;



events {
    worker_connections  1024;
}


http {
    include      mime.types;
    default_type  application/octet-stream;
    sendfile        off;
    keepalive_timeout  65;
    gzip off;

    server {
        root /usr/local/www;
        location = /robots.txt { allow all; access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }
        location ^~ /owncloud {
            index index.php;
            try_files $uri $uri/ /owncloud/index.php$is_args$args;
            client_max_body_size 512M;
            location ~ ^/owncloud/(?:\.|data|config|db_structure\.xml|README) {
                deny all;
            }
            location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                include fastcgi_params;
                fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
            }
            location ~* \.(?:jpg|gif|ico|png|css|js|svg)$ {
                expires 30d; add_header Cache-Control public;
            }
            location ^~ /owncloud/data {
                internal;
                alias /mnt/files;
            }
        }
    }
}


My ownCloud location is at /mnt/zdrive/ownCloud if that matters.
Where are your files mounted to inside the jail? the usual /mnt/files or somewhere else?
 

Chakalov

Explorer
Joined
Feb 9, 2015
Messages
53
Yes, exactly there. I can browse through the /mnt/files and see all user directories and files
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Yes, exactly there. I can browse through the /mnt/files and see all user directories and files
Are you using owncloud 7 or 8?
 
Top