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

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Hi,
I completed install and followed the earlier post to make it a owncloud.mydomain.com but when I go to the webgui I am prompted to download an octet file. This is my nginx.conf
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/owncloud;  
          location = /robots.txt { allow all; access_log off; log_not_found off; }
          location = /favicon.ico { access_log off; log_not_found off; }  
                  index index.php;  
                  try_files $uri $uri/ /index.php$is_args$args;  
                  client_max_body_size 512M;  
                  location ~ ^/(?:\.|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 ^/data {  
                      internal;  
                      alias /mnt/files;  
                  }  
              }  
      }


If I use the original conf I get this error
I don't see anything wrong there... maybe try browsing to http://owncloud.mydomain.com/index.php

on your step using the /owncloud config you made a mistake somewhere. you could post that and I can comment of you like.
 

csjjpm

Contributor
Joined
Feb 16, 2015
Messages
126
Hi Joshua,
I think it is an issue with PHP not being interpreted.
I created a phpinfo file
Code:
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>


and it prompted me to save the file.
Paul
 

csjjpm

Contributor
Joined
Feb 16, 2015
Messages
126
I followed your isntructions now on two jails and got the same result. I did all the pkg update stuff and portsnap stuff. Has that screwed things up?

This is what I get from 'top'
last pid: 22128; load averages: 0.03, 0.01, 0.00 up 3+05:05:22 14:33:42
14 processes: 1 running, 13 sleeping
CPU: 0.1% user, 0.0% nice, 0.0% system, 0.0% interrupt, 99.9% idle
Mem: 301M Active, 869M Inact, 13G Wired, 6624K Cache, 1093M Free
ARC: 11G Total, 2169M MFU, 8082M MRU, 560K Anon, 199M Header, 1090M Other
Swap: 10G Total, 57M Used, 10G Free
PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND
20874 mysql 23 52 0 526M 94544K sigwai 4 0:00 0.00% mysqld
22117 root 1 20 0 18672K 2424K CPU3 3 0:00 0.00% top
20756 www 1 20 0 25092K 5448K kqread 0 0:00 0.00% nginx
22115 root 1 20 0 17572K 3456K pause 1 0:00 0.00% csh
20747 root 1 20 0 308M 26108K kqread 1 0:00 0.00% php-fpm
20764 mysql 1 52 0 14544K 2248K wait 5 0:00 0.00% sh
20701 root 1 20 0 12092K 1880K select 4 0:00 0.00% syslogd
20883 root 1 20 0 14188K 1880K nanslp 0 0:00 0.00% cron
20226 root 1 52 0 12088K 1928K select 0 0:00 0.00% dhclient
20755 www 1 20 0 25092K 5452K kqread 1 0:00 0.00% nginx
20748 www 1 52 0 308M 26128K accept 4 0:00 0.00% php-fpm
20754 root 1 52 0 25092K 5000K pause 6 0:00 0.00% nginx
20749 www 1 52 0 308M 26128K accept 5 0:00 0.00% php-fpm
20310 _dhcp 1 20 0 12088K 1980K select 1 0:00 0.00% dhclient
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I followed your isntructions now on two jails and got the same result. I did all the pkg update stuff and portsnap stuff. Has that screwed things up?

This is what I get from 'top'
Just to double check, your restarting nginx after setting your config up? Maybe remove the default_type and see if that changes things.
 

SmallGuy

Guru
Joined
Jun 7, 2013
Messages
560
This behavior occur because your php files are proceed by nginx instead of php-fpm.
In other words, your location .php/nanana is broken and your request is proceed by nginx with the default location of your nginx configuration file (the first which match the request).
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
This behavior occur because your php files are proceed by nginx instead of php-fpm.
In other words, your location .php/nanana is broken and your request is proceed by nginx with the default location of your nginx configuration file (the first which match the request).
This is what I suspect too, but I can't find the issue. Examining his config, it looks the same as the posted one.
 

SmallGuy

Guru
Joined
Jun 7, 2013
Messages
560
or php-fpm doesn't work at all
 

Joshua Parker Ruehlig

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

SmallGuy

Guru
Joined
Jun 7, 2013
Messages
560
Perhaps parameters in php.ini are incorrect. And php-fpm doesn't find the file.
 

SmallGuy

Guru
Joined
Jun 7, 2013
Messages
560
Docroot, script filename or path info
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Perhaps parameters in php.ini are incorrect. And php-fpm doesn't find the file.
No, like I said above this is before php gets to process the file. This is specifically nginx not passing the request and choosing to serve it itself. If his php configs were off he would get different behavior
 

csjjpm

Contributor
Joined
Feb 16, 2015
Messages
126
Hi Joshua (and everyone else),
I tried commenting out default_type and that din't help.
I am doing a service nginx restart between every change.
Oddly this morning when I go to the website I get this
Code:
<?php

/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/

// Show warning if a PHP version below 5.4.0 is used, this has to happen here
// because base.php will already use 5.4 syntax.
if (version_compare(PHP_VERSION, '5.4.0') === -1) {
    echo 'This version of ownCloud requires at least PHP 5.4.0<br/>';
    echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
    return;
}

try {
   
    require_once 'lib/base.php';

    OC::handleRequest();

} catch(\OC\ServiceUnavailableException $ex) {
    \OCP\Util::logException('index', $ex);

    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    OC_Template::printExceptionErrorPage($ex);
} catch (\OC\HintException $ex) {
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    OC_Template::printErrorPage($ex->getMessage(), $ex->getHint());
} catch (Exception $ex) {
    \OCP\Util::logException('index', $ex);

    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
    OC_Template::printExceptionErrorPage($ex);
}


I am going to trash the jails I have and start again, maybe third time lucky!
 

LarsHalbauer

Cadet
Joined
Feb 28, 2015
Messages
7
Hi there,

I'm experiencing the same exact problem.
When I navigate to http://--jail.ip--/owncloud nothing happens or I get the php-error described above.
I'm using FreeNAS 9.1.7 with OC 8 (fresh install).

These are the two config-files for nginx:

Variant 1 - getting a blank page and server not responding:
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/owncloud;                                                                                             
        location = /robots.txt { allow all; access_log off; log_not_found off; }                                                  
        location = /favicon.ico { access_log off; log_not_found off; }                                                            
            index index.php;                                                                                                      
            try_files $uri $uri/ /index.php$is_args$args;                                                                         
            client_max_body_size 10G;                                                                                             
            location ^/(?:\.|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 ^/data {                                                                                                     
                internal;                                                                                                         
                alias /mnt/files;                                                                                                 
            }                                                                                                                     
    }                                                                                                                             
}                                                                                                                                 
      

Variant 2 - PHP-Error (adapted from owncloud.org):
Code:
worker_processes 2;

events {
worker_connections 1024;
}

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

#SSL
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
ssl_prefer_server_ciphers on;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
upstream php-handler {
server unix:/var/run/php5-fpm.sock;
#server unix:/var/run/php5-fpm.sock;
}

server {
listen 80;
server_name -myservername- 192.168.0.x;
# enforce https
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name -myservername- 192.168.0.x;

ssl_certificate /usr/local/etc/nginx/ssl-bundle.crt;
ssl_certificate_key /usr/local/etc/nginx/server.key;


# Path to the root of your installation
root /usr/local/www/owncloud/;
# set max upload size
client_max_body_size 10G;
fastcgi_buffers 64 4K;

rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

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

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

location ^/(?:\.htaccess|data|config|db_structure\.xml|README){
deny all;
}

location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;

rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

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

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 php-handler;
}

# 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;
}

}
}

This time I tried it for the third time, following all the steps described in the first post before, but I still cant get access to the main webpage.
Any help would be greatly appreciated and thanks in advance fr any helpful tips or hints.
 

SmallGuy

Guru
Joined
Jun 7, 2013
Messages
560
I don't have check the regex, but some details looks falses to me:
Variant 1:
your fastcgi parameter include is loaded after your fastcgi parameters configuration, so the latter are overwritten.
If I remember correctly , fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED is broken with OC8.
You are better with:
Code:
location \.php(?:$|/) {   
   fastcgi_split_path_info ^(.+\.php)(/.*)$;   
   fastcgi_pass unix:/var/run/php-fpm.sock;   
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   
   fastcgi_param PATH_INFO $fastcgi_path_info;   
   fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED off;   
   }
 

LarsHalbauer

Cadet
Joined
Feb 28, 2015
Messages
7
Unfortunately, this didn't help. But in my distress I replaced
Code:
fastcgi_pass unix:/var/run/php-fpm.sock;  

with

Code:
fastcgi_pass 127.0.0.1:9000;  


Now nginx passes the php-request to php and I see the installation screen. :D:D

But now the My SQL Configuration seems to be broken, because it says
Code:
MySQL/MariaDB username and/or password not valid You need to enter either an existing account or the administrator.


though I passed the right combination of username/pw.
Endless story, round 2.

Any help is appreciated.
 

Darkk

Dabbler
Joined
Mar 29, 2014
Messages
32
Just got through reading several posts here to see if there is a solution to the problem with OC7 going to OC8 upgrade only to be greeted with a blank page. I had everything working in version 7 and thought would be cool to upgrade to version 8. Nope. lol.

So I've basically used the standard ngnix.conf with that fast MOD X accel enable to off. For some strange reason I am getting this in the error log:

*5 FastCGI sent in stderr: "Unable to open primary script: /usr/local/www/owncloud/owncloud/status.php (No such file or directory)" while reading response header from upstream, client: 192.168.1.15, server: test.owncloud.local, request: "GET /owncloud/status.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "192.168.1.15"

Since I don't have additional webs in ngnix so I pointed everything to root /usr/local/www/owncloud;
And removed any "/owncloud" in the ngnix.conf file.

Like I said it was working fine in version 7. After few posts it seems some changes in version 8 which broke in ngnix? Looks like it's putting another "/owncloud" in the link as shown above?


Here is the current nginx.config:

server {
listen 443 default ssl;
root /usr/local/www/owncloud;
location = /robots.txt { allow all; access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
client_max_body_size 512M;
location ~ ^/(?:\.|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;
fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED off;
include fastcgi_params;
}
location ~* \.(?:jpg|gif|ico|png|css|js|svg)$ {
expires 30d; add_header Cache-Control public;
}
location ^~ /data {
internal;
alias /mnt/jailowncloud;
}
}
}
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Unfortunately, this didn't help. But in my distress I replaced
Code:
fastcgi_pass unix:/var/run/php-fpm.sock; 

with

Code:
fastcgi_pass 127.0.0.1:9000; 


Now nginx passes the php-request to php and I see the installation screen. :D:D

But now the My SQL Configuration seems to be broken, because it says
Code:
MySQL/MariaDB username and/or password not valid You need to enter either an existing account or the administrator.


though I passed the right combination of username/pw.
Endless story, round 2.

Any help is appreciated.
You did follow the guide exactly if you have php-fpm listening on a port instead of a socket.

You can always destroy and recreate the database on the mysql commandline to make sure the credentials you are using match.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Just got through reading several posts here to see if there is a solution to the problem with OC7 going to OC8 upgrade only to be greeted with a blank page. I had everything working in version 7 and thought would be cool to upgrade to version 8. Nope. lol.

So I've basically used the standard ngnix.conf with that fast MOD X accel enable to off. For some strange reason I am getting this in the error log:

*5 FastCGI sent in stderr: "Unable to open primary script: /usr/local/www/owncloud/owncloud/status.php (No such file or directory)" while reading response header from upstream, client: 192.168.1.15, server: test.owncloud.local, request: "GET /owncloud/status.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "192.168.1.15"

Since I don't have additional webs in ngnix so I pointed everything to root /usr/local/www/owncloud;
And removed any "/owncloud" in the ngnix.conf file.

Like I said it was working fine in version 7. After few posts it seems some changes in version 8 which broke in ngnix? Looks like it's putting another "/owncloud" in the link as shown above?


Here is the current nginx.config:

server {
listen 443 default ssl;
root /usr/local/www/owncloud;
location = /robots.txt { allow all; access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
client_max_body_size 512M;
location ~ ^/(?:\.|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;
fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED off;
include fastcgi_params;
}
location ~* \.(?:jpg|gif|ico|png|css|js|svg)$ {
expires 30d; add_header Cache-Control public;
}
location ^~ /data {
internal;
alias /mnt/jailowncloud;
}
}
}
The status.php problem is a know issue. OC 8.0.0 has alot of known bugs right now =/
https://forum.owncloud.org/viewtopic.php?f=31&t=26310
 

Darkk

Dabbler
Joined
Mar 29, 2014
Messages
32

neto_hugo

Explorer
Joined
Mar 6, 2012
Messages
87
Guys, again a problem with port forwarding. But I do not know how to fix it. :oops:

The address https://mydomain.com/owncloud is to ensure access to the OC and is working quiet well. But when I try to mydomain.com which was to access the FreeNAS I am getting a warning "Welcome to nginx."

In /usr/local/etc/nginx/nginx.conf I setup the SSL port 443 to the OC and the FreeNAS WebGUI the door 446. In my router I forwarding 443 port to the IP of the OC.

Where am I going wrong?
 
Top