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

Dwight Turner

Explorer
Joined
Oct 13, 2014
Messages
76
hmm so easy ..

by the way my owncloud is running tops with your instructions. thanks again!
 

omstauf

Cadet
Joined
Jun 4, 2016
Messages
7
Okay... So I did this a few days ago on my own rig, setting up owncloud then making it hardened with TSL. After some errors and reinstallation of packages, I had my rig done and working nicely. Thanks for the quick way, which, if you know what most things do, you can tweak as needed. =)

Nutshell version at the bottom....

Then I setup a buddies Freenas box and tried owncloud, to some errors which I gave up on initially (this is before I redid my own rig). So I had time today to redo his rig and you go and change the php packages to version 7... I fought with nginx, ssl, owncloud, php, and freenas all day..... I had it to a point where it worked at the local ip unsecure. Secured it and it borked.. Redid it... Ended up with 502 errors, which became 404 after trying the fix you suggested.

I was ready to kill the box with whatever I could grab... So, I hosed everything, once again, and proceeded another time paying attention to the packaging system and compilers.. Well... The issue, at least with this box, and I'd bet others, is that when you follow to install Libreoffice, it borks PHP as it kills it and installs a basic 5.6 package which then cascades everything.. To fix, I just reinstalled all the v7 packages and like magic everything worked... Well, except his crappy at&t modem, but that's tomorrow...

So, nutshell... If you install Libreoffice or maybe ffmpeg (doubtful tho), make sure you reinstall the php v7 packages..

Another thing I noticed, was your line #3 on jail pkg installers, It didn't do anything today and might have said not-found, I honestly don't remember. As such, I omitted the two lines in the config for memcache.

Not entirely sure what either of those really do, but seems to work without it.. Although I still can't get doc editing or video previews to work with ffmpeg or libre... Suggestions?

Overall, thanks for the write-up and support! Now, do I upgrade my rig to php v7... lol
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Okay... So I did this a few days ago on my own rig, setting up owncloud then making it hardened with TSL. After some errors and reinstallation of packages, I had my rig done and working nicely. Thanks for the quick way, which, if you know what most things do, you can tweak as needed. =)

Nutshell version at the bottom....

Then I setup a buddies Freenas box and tried owncloud, to some errors which I gave up on initially (this is before I redid my own rig). So I had time today to redo his rig and you go and change the php packages to version 7... I fought with nginx, ssl, owncloud, php, and freenas all day..... I had it to a point where it worked at the local ip unsecure. Secured it and it borked.. Redid it... Ended up with 502 errors, which became 404 after trying the fix you suggested.

I was ready to kill the box with whatever I could grab... So, I hosed everything, once again, and proceeded another time paying attention to the packaging system and compilers.. Well... The issue, at least with this box, and I'd bet others, is that when you follow to install Libreoffice, it borks PHP as it kills it and installs a basic 5.6 package which then cascades everything.. To fix, I just reinstalled all the v7 packages and like magic everything worked... Well, except his crappy at&t modem, but that's tomorrow...

So, nutshell... If you install Libreoffice or maybe ffmpeg (doubtful tho), make sure you reinstall the php v7 packages..

Another thing I noticed, was your line #3 on jail pkg installers, It didn't do anything today and might have said not-found, I honestly don't remember. As such, I omitted the two lines in the config for memcache.

Not entirely sure what either of those really do, but seems to work without it.. Although I still can't get doc editing or video previews to work with ffmpeg or libre... Suggestions?

Overall, thanks for the write-up and support! Now, do I upgrade my rig to php v7... lol
yeah, i hate these heavy dependencies like libreoffice. and sometime the package/build servers make things supper complicated by adding extra unneeded dependencies.
One thing that helps is 'pkg delete -f' to delete dependencies a package thinks it needs, then install your own.

I guess I forgot to mention you now also have to enable preivew providers for most file types. This is what my config.php looks like.
Code:
  'enable_previews' => true,
  'enabledPreviewProviders' =>
  array (
  0 => 'OC\\Preview\\PNG',
  1 => 'OC\\Preview\\JPEG',
  2 => 'OC\\Preview\\GIF',
  3 => 'OC\\Preview\\BMP',
  4 => 'OC\\Preview\\XBitmap',
  5 => 'OC\\Preview\\Markdown',
  6 => 'OC\\Preview\\MP3',
  7 => 'OC\\Preview\\TXT',
  8 => 'OC\\Preview\\Illustrator',
  9 => 'OC\\Preview\\Movie',
  10 => 'OC\\Preview\\MSOffice2003',
  11 => 'OC\\Preview\\MSOffice2007',
  12 => 'OC\\Preview\\MSOfficeDoc',
  13 => 'OC\\Preview\\OpenDocument',
  14 => 'OC\\Preview\\PDF',
  15 => 'OC\\Preview\\Photoshop',
  16 => 'OC\\Preview\\Postscript',
  17 => 'OC\\Preview\\StarOffice',
  18 => 'OC\\Preview\\SVG',
  19 => 'OC\\Preview\\TIFF',
  20 => 'OC\\Preview\\Font',
  ),

When you say doc editing, you mean .DOC format right? You also need to enable this in the admin settings page.
 

omstauf

Cadet
Joined
Jun 4, 2016
Messages
7
yeah, i hate these heavy dependencies like libreoffice. and sometime the package/build servers make things supper complicated by adding extra unneeded dependencies.
One thing that helps is 'pkg delete -f' to delete dependencies a package thinks it needs, then install your own.

I guess I forgot to mention you now also have to enable preivew providers for most file types. This is what my config.php looks like.
Code:
  'enable_previews' => true,
  'enabledPreviewProviders' =>
  array (
  0 => 'OC\\Preview\\PNG',
  1 => 'OC\\Preview\\JPEG',
  2 => 'OC\\Preview\\GIF',
  3 => 'OC\\Preview\\BMP',
  4 => 'OC\\Preview\\XBitmap',
  5 => 'OC\\Preview\\Markdown',
  6 => 'OC\\Preview\\MP3',
  7 => 'OC\\Preview\\TXT',
  8 => 'OC\\Preview\\Illustrator',
  9 => 'OC\\Preview\\Movie',
  10 => 'OC\\Preview\\MSOffice2003',
  11 => 'OC\\Preview\\MSOffice2007',
  12 => 'OC\\Preview\\MSOfficeDoc',
  13 => 'OC\\Preview\\OpenDocument',
  14 => 'OC\\Preview\\PDF',
  15 => 'OC\\Preview\\Photoshop',
  16 => 'OC\\Preview\\Postscript',
  17 => 'OC\\Preview\\StarOffice',
  18 => 'OC\\Preview\\SVG',
  19 => 'OC\\Preview\\TIFF',
  20 => 'OC\\Preview\\Font',
  ),

When you say doc editing, you mean .DOC format right? You also need to enable this in the admin settings page.

Thanks for the tidbits on trying to wrangle the pkg manager! I last used FreeBSD with 4.8 and at that, I never used any features beyond v4.2. I just liked make worlding back then for some odd reason..

By .doc format, I didn't mean that literally, more just standard/typical file formats in general. Should I presume that 'Movie' refers to avi/mp4, or does it mean that horrid apple .mov format?

Thanks again!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Thanks for the tidbits on trying to wrangle the pkg manager! I last used FreeBSD with 4.8 and at that, I never used any features beyond v4.2. I just liked make worlding back then for some odd reason..

By .doc format, I didn't mean that literally, more just standard/typical file formats in general. Should I presume that 'Movie' refers to avi/mp4, or does it mean that horrid apple .mov format?

Thanks again!
you should be able to live edit documents, which are in ODT format as soon as you install the documents app. nothing special you need to do...

Yeah MP4's and AVI's on my system get a thumbnail preview. Not sure about MOV, lol
 

adrianwi

Guru
Joined
Oct 15, 2013
Messages
1,231
Anyone considering or have moved their FreeNAS ownCloud to NextCloud?

From what I can see on the NextCloud forum there's still some issues with nginx installations and the upgrade not always running smoothly, but press reports suggest it might be the better horse to back?

Might have a crack at cloning one of my snapshots into a new jail and see if the grass looks greener....
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I think we fixed the nginx config issue last week, otherwise theyd still be bugging me.

I'm thinking of switching eventually, but personally waiting for things to play out a bit more.
 

DumDum

Dabbler
Joined
Feb 24, 2015
Messages
11
Hello,

I am having one heck of a problem that I just don't know enough to dig myself out of. I've noticed that certain icons were not being displayed and by looking at /var/log/nginx-error.log

Code:
2016/07/05 21:32:22 [error] 363#100995: *1061 open() "/usr/local/www/apps/calendar/img/calendar.svg" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /apps/calendar/img/calendar.svg HTTP/1.1", 
2016/07/05 21:32:22 [error] 366#100687: *1062 open() "/usr/local/www/apps/external/img/external.png" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /apps/external/img/external.png HTTP/1.1"
2016/07/05 21:32:22 [error] 366#100687: *1066 open() "/usr/local/www/settings/img/apps.svg" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /settings/img/apps.svg HTTP/1.1"
2016/07/05 21:32:22 [error] 366#100687: *1065 open() "/usr/local/www/themes/theme/core/img/actions/delete.svg" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /themes/theme/core/img/actions/delete.svg HTTP/1.1"
2016/07/05 21:32:23 [error] 363#100995: *1068 open() "/usr/local/www/themes/theme/core/img/favicon.ico" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /themes/theme/core/img/favicon.ico HTTP/1.1"
2016/07/05 21:32:23 [error] 363#100995: *1068 open() "/usr/local/www/favicon.ico" failed (2: No such file or directory), client: 192.168.1.1, request: "GET /favicon.ico HTTP/1.1"


Below is my current nginx.conf, any assistance would be greatly appreciated. My current goal is to have owncloud in a subdirectory: "https://my.domain/owncloud" however, per the nginx-error.log shown above the requests are not going to the correct directory: /usr/local/www/owncloud

...hopefully this all makes sense to someone as you can see I made a real mess

Code:
    worker_processes 8;

    events {
        worker_connections  1024;
    }

    http {
        include      mime.types;
        default_type  application/octet-stream;
        sendfile        off;
        keepalive_timeout  65;
        gzip off;
        ssl_dhparam /usr/local/etc/nginx/dhparams.pem;
        ssl_certificate /usr/local/etc/nginx/localhost.pem;
        ssl_certificate_key /usr/local/etc/nginx/localhost.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS";
        # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
        add_header Strict-Transport-Security max-age=15768000;
        # End of Generated
server {
    listen 80;
    
    # enforce https
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl;
    

    # Add headers to serve security related headers
    add_header Strict-Transport-Security "max-age=0; includeSubDomains; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;

    # Path to the root of your website (one level above owncloud folder)
    root /usr/local/www;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ^~ /owncloud {
        # set max upload size
        client_max_body_size 10G;
        fastcgi_buffers 64 4K;

        error_page 403 /owncloud/core/templates/403.php;
        error_page 404 /owncloud/core/templates/404.php;

        location /owncloud {
            rewrite ^ /owncloud/index.php$uri;
        }
        location ~ ^/owncloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/owncloud/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }
#        location ~ ^/owncloud/(?:\.htaccess|data|config|db_structure\.xml|README) {
#            deny all;
#        }

        rewrite ^/owncloud/caldav(.*)$ /owncloud/remote.php/caldav$1 redirect;
        rewrite ^/owncloud/carddav(.*)$ /owncloud/remote.php/carddav$1 redirect;
        rewrite ^/owncloud/webdav(.*)$ /owncloud/remote.php/webdav$1 redirect;
        rewrite ^/owncloud/core/doc/([^\/]+)(?:$|/) /owncloud/core/doc/$1/index.html;

#        try_files $uri $uri/ /owncloud/index.php;

         location ~ ^/owncloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
             fastcgi_split_path_info ^(.+\.php)(/.*)$;
             include fastcgi_params;
             fastcgi_pass unix:/var/run/php-fpm.sock;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             fastcgi_param PATH_INFO $fastcgi_path_info;
             fastcgi_param front_controller_active true;
             fastcgi_intercept_errors on;
         }

#        location ~ \.php(?:$|/) {
#            fastcgi_split_path_info ^(.+\.php)(/.+)$;
#            include fastcgi_params;
#            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#            fastcgi_param PATH_INFO $fastcgi_path_info;
#            fastcgi_param HTTPS on;
#            fastcgi_pass unix:/var/run/php-fpm.sock;
#        }

        # Optional: set long EXPIRES header on static assets
#        location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
#            expires 30d;
#            # Optional: Don't log access to assets
#            access_log off;
#        }
        location ~* \.(?:css|js)$ {
            try_files $uri /owncloud/index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=7200";
        }
        location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
            try_files $uri /owncloud/index.php$uri$is_args$args;
        }

    }

}
}
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
@DumDum it looks like owncloud is requesting the wrong URLs, not something wrong with your nginx config. I'd check /usr/local/www/owncloud/config/config.php to make sure nothing looks strange there.
owncloud forum might be able to help as well, why owncloud isn't picking up the webroot.
 

DumDum

Dabbler
Joined
Feb 24, 2015
Messages
11
@Joshua Parker Ruehlig
Thank you kind sir for taking the time to reply, it is now fixed! I wish I could tell you how things went wrong, but I just grabbed the latest owncloud and performed a manual upgrade and all is well.

On another note, I too am curious if anyone has any good experiences with migrating to nextcloud. Though I am patiently waiting as owncloud has served me well through the last couple of years and have no real reason to jump ship.
 

tamilmad

Dabbler
Joined
Oct 20, 2015
Messages
36
I think we fixed the nginx config issue last week, otherwise theyd still be bugging me.

I'm thinking of switching eventually, but personally waiting for things to play out a bit more.
I would be thinking of switching to Nextcloud only after you make the move and post the instructions for the same !
 

Perm1990

Dabbler
Joined
Feb 25, 2016
Messages
43
Hello.
Thank you to Joshua for helpful guide.

I was success full until this step:
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set memcache.local --value="\OC\Memcache\APCu"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set redis host --value="/tmp/redis.sock"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set redis port --value=0 --type=integer'

Before that I saw OwnCloud interface. After those 4 lines just:
<!DOCTYPE html>
<!--[if lte IE 8]><html class="ng-csp ie ie8 lte9 lte8" data-placeholder-focus="false" lang="de_DE" ><![endif]-->
<!--[if IE 9]><html class="ng-csp ie ie9 lte9" data-placeholder-focus="false" lang="de_DE" ><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html class="ng-csp" data-placeholder-focus="false" lang="de_DE" ><!--<![endif]-->
<head data-requesttoken="">
<meta charset="utf-8">
<title>
ownCloud </title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="referrer" content="never">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-itunes-app" content="app-id=543672169">
<meta name="theme-color" content="#1d2d44">
<link rel="shortcut icon" href="Memcache \OC\Memcache\APCu not available for local cache Is the matching PHP module installed and enabled?

So, what is wrong here?

Many thanks in advanced.

Update: It seems, that the cause is the failed
make config-recursive install clean -C /usr/ports/security/pecl-APCu

Currently, there is not such directory to compile.
 
Last edited:

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Hello.
Thank you to Joshua for helpful guide.

I was success full until this step:
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set memcache.local --value="\OC\Memcache\APCu"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set memcache.locking --value="\OC\Memcache\Redis"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set redis host --value="/tmp/redis.sock"'
su -m www -c 'php /usr/local/www/owncloud/occ config:system:set redis port --value=0 --type=integer'

Before that I saw OwnCloud interface. After those 4 lines just:
<!DOCTYPE html>
<!--[if lte IE 8]><html class="ng-csp ie ie8 lte9 lte8" data-placeholder-focus="false" lang="de_DE" ><![endif]-->
<!--[if IE 9]><html class="ng-csp ie ie9 lte9" data-placeholder-focus="false" lang="de_DE" ><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html class="ng-csp" data-placeholder-focus="false" lang="de_DE" ><!--<![endif]-->
<head data-requesttoken="">
<meta charset="utf-8">
<title>
ownCloud </title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="referrer" content="never">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-itunes-app" content="app-id=543672169">
<meta name="theme-color" content="#1d2d44">
<link rel="shortcut icon" href="Memcache \OC\Memcache\APCu not available for local cache Is the matching PHP module installed and enabled?

So, what is wrong here?

Many thanks in advanced.
Hmm, I realized the APCu port isn't updated for PHP7. See here https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207462

You need to do the following to get it to work.
* edit /usr/ports/devel/pecl-APCu/Makefile and change 'PORTVERSION' to 5.1.5
Code:
make makesum config-recursive install clean -C /usr/ports/devel/pecl-APCu
 
Last edited:

Perm1990

Dabbler
Joined
Feb 25, 2016
Messages
43

Joshua Parker Ruehlig

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

In my jail, there is no such directory /usr/ports/security/pecl-APCu
no wonder you couldn't build the port, lol.
portsnap fetch extract
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I did 'portsnap fetch extract'.

Even after that there are just
root@MyCloud:/usr/ports/security # cd pecl-
pecl-crack/ pecl-crypto/ pecl-gnupg/ pecl-pam/ pecl-scrypt/ pecl-ssh2/ pecl-taint/ pecl-tcpwrap/
whoops, typo. that should be devel/pecl-APCu. I'll fix it in the various posts.
 

Perm1990

Dabbler
Joined
Feb 25, 2016
Messages
43
whoops, typo. that should be devel/pecl-APCu. I'll fix it in the various posts.

Ok. We moving further :)
make config-recursive install clean -C /usr/ports/devel/pecl-APCu

The make stops here:
===> pecl-APCu-5.1.5 cannot be installed: doesn't work with lang/php70 port
(doesn't support PHP 70).
*** Error code 1
Stop.
make: stopped in /usr/ports/devel/pecl-APCu

I just used default options for make.
 
Top