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

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Everything was working perfectly till I rebooted the server. Now I'm getting these errors in my nginx.conf file
Code:
2017/01/15 07:53:45 [crit] 82691#102236: *15 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$
2017/01/15 07:54:17 [crit] 82691#102236: *17 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$
2017/01/15 07:54:49 [crit] 82691#102236: *19 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$

I've restart nginx, php-fpm, mysql-server and redis without any help. Still getting 502 error on the web page.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
@KevDog you can edit users crobtabs with 'crontab -e', this installs them as well.
also you can just use 'service nginx restart' instead of always doing stop, then start
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Everything was working perfectly till I rebooted the server. Now I'm getting these errors in my nginx.conf file
Code:
2017/01/15 07:53:45 [crit] 82691#102236: *15 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$
2017/01/15 07:54:17 [crit] 82691#102236: *17 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$
2017/01/15 07:54:49 [crit] 82691#102236: *19 connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.1, server: 192.168.1.180, request: "GET /nextcloud/status.php HTTP/1.1", upstream: "fastcgi://unix$

I've restart nginx, php-fpm, mysql-server and redis without any help. Still getting 502 error on the web page.
what does 'sockstat' show?
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
@Joshua -- Thanks for tip :). Just figuring out the BSD way of doing things -- not quite like linux. With cron however -- I wanted the system crontab -- not any user or the root user. I don't know a method of doing this other than editing either the /etc/crontab or the files located in /etc/periodic/. I don't think these run as a particular user --- or perhaps they do. I'm not sure.

@NasKar -- I'd listen to Joshua on this one -- I restarted everything after you scared me, and everything here came up running as expected. There are a lot of variables right now that could be causing this.
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
what does 'sockstat' show?
Code:
USER	 COMMAND	PID   FD PROTO  LOCAL ADDRESS		 FOREIGN ADDRESS	  
www	  php-fpm	90004 0  tcp4   127.0.0.1:9000		*:*
www	  php-fpm	90003 0  tcp4   127.0.0.1:9000		*:*
root	 php-fpm	90002 4  stream -> ??
root	 php-fpm	90002 6  stream -> ??
root	 php-fpm	90002 7  tcp4   127.0.0.1:9000		*:*
www	  nginx	  89157 3  stream -> ??
www	  nginx	  89157 7  tcp4   *:80				  *:*
www	  nginx	  89157 8  tcp4   *:443				 *:*
www	  nginx	  89157 9  tcp4   192.168.1.180:80	  192.168.1.8:39128
www	  nginx	  89157 10 tcp4   192.168.1.180:443	 192.168.1.1:39129
www	  nginx	  89157 11 stream -> ??
www	  nginx	  89156 3  stream -> ??
www	  nginx	  89156 7  tcp4   *:80				  *:*
www	  nginx	  89156 8  tcp4   *:443				 *:*
www	  nginx	  89156 9  stream -> ??
root	 nginx	  89155 3  stream -> ??
root	 nginx	  89155 7  tcp4   *:80				  *:*
root	 nginx	  89155 8  tcp4   *:443				 *:*
root	 nginx	  89155 9  stream -> ??
root	 nginx	  89155 10 stream -> ??
root	 nginx	  89155 11 stream -> ??
redis	redis-serv 82441 4  stream /tmp/redis.sock
mysql	mysqld	 82411 21 stream /tmp/mysql.sock
root	 cron	   80746 4  dgram  -> /var/run/logpriv
root	 syslogd	80561 4  dgram  /var/run/log
root	 syslogd	80561 5  dgram  /var/run/logpriv
root	 syslogd	80561 6  udp6   *:514				 *:*
root	 syslogd	80561 7  udp4   *:514				 *:*

 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
@Jailer -- Good to know all the information -- I'll add it!!! A lot of misinformation disseminated over the thread.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Code:
USER	 COMMAND	PID   FD PROTO  LOCAL ADDRESS		 FOREIGN ADDRESS	 
www	  php-fpm	90004 0  tcp4   127.0.0.1:9000		*:*
www	  php-fpm	90003 0  tcp4   127.0.0.1:9000		*:*
root	 php-fpm	90002 4  stream -> ??
root	 php-fpm	90002 6  stream -> ??
root	 php-fpm	90002 7  tcp4   127.0.0.1:9000		*:*
www	  nginx	  89157 3  stream -> ??
www	  nginx	  89157 7  tcp4   *:80				  *:*
www	  nginx	  89157 8  tcp4   *:443				 *:*
www	  nginx	  89157 9  tcp4   192.168.1.180:80	  192.168.1.8:39128
www	  nginx	  89157 10 tcp4   192.168.1.180:443	 192.168.1.1:39129
www	  nginx	  89157 11 stream -> ??
www	  nginx	  89156 3  stream -> ??
www	  nginx	  89156 7  tcp4   *:80				  *:*
www	  nginx	  89156 8  tcp4   *:443				 *:*
www	  nginx	  89156 9  stream -> ??
root	 nginx	  89155 3  stream -> ??
root	 nginx	  89155 7  tcp4   *:80				  *:*
root	 nginx	  89155 8  tcp4   *:443				 *:*
root	 nginx	  89155 9  stream -> ??
root	 nginx	  89155 10 stream -> ??
root	 nginx	  89155 11 stream -> ??
redis	redis-serv 82441 4  stream /tmp/redis.sock
mysql	mysqld	 82411 21 stream /tmp/mysql.sock
root	 cron	   80746 4  dgram  -> /var/run/logpriv
root	 syslogd	80561 4  dgram  /var/run/log
root	 syslogd	80561 5  dgram  /var/run/logpriv
root	 syslogd	80561 6  udp6   *:514				 *:*
root	 syslogd	80561 7  udp4   *:514				 *:*

it shows what is listening in your jail. your php-fpm is configured to listen on a port not /var/run/php-fpm.sock. youlle want to check you editing the configuration file as instructed.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
it shows what is listening in your jail. your php-fpm is configured to listen on a port not /var/run/php-fpm.sock. youlle want to check you editing the configuration file as instructed.
/var/run/php-fpm.sock doesn't exist at /var/run/
Code:
/var/run # ls -l
total 17
-rw-r--r--  1 root   wheel	  0 Jan 15 07:42 clean_var
-rw-------  1 root   wheel	  5 Jan 15 07:42 cron.pid
drwxr-xr-x  3 root   wheel	  3 Jan 10 18:36 cups
drwxr-xr-x  2 root   wheel	  2 Jan 10 18:34 dbus
-r--r--r--  1 root   wheel	326 Jan 15 07:42 ld-elf.so.hints
-r--r--r--  1 root   wheel	139 Jan 15 07:42 ld-elf32.so.hints
srw-rw-rw-  1 root   wheel	  0 Jan 15 07:42 log
srw-------  1 root   wheel	  0 Jan 15 07:42 logpriv
-rw-r--r--  1 root   wheel	  6 Jan 15 08:00 nginx.pid
-rw-r--r--  1 root   wheel	  5 Jan 15 08:20 php-fpm.pid
drwxrwx---  2 root   network	2 Mar 24  2016 ppp
drwxr-xr-x  2 redis  redis	  3 Jan 15 07:46 redis
-rw-------  1 root   wheel	  5 Jan 15 07:42 syslog.pid
-rw-r--r--  1 root   wheel	  0 Jan 15 07:42 syslogd.sockets
drwx------  2 _tss   _tss	   2 Jan  2 20:36 tpm
-rw-r--r--  1 root   wheel	197 Jan 15 07:42 utx.active
drwxr-xr-x  2 root   wheel	  2 Mar 24  2016 wpa_supplicant

 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Fix your configuration file. It's one of the instruction on the first page of this tutorial.

Edit: /usr/local/etc/php-fpm.d/www.conf
Find: listen = 127.0.0.1:9000
Change to : listen = /var/run/php-fpm.sock
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Fix your configuration file. It's one of the instruction on the first page of this tutorial.

Edit: /usr/local/etc/php-fpm.d/www.conf
Find: listen = 127.0.0.1:9000
Change to : listen = /var/run/php-fpm.sock
That's already what is there. My setup was working great till I rebooted. Here is my www.conf segment.
Code:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'	- to listen on a TCP socket to a specific IPv4 address on
;							a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;							a specific port;
;   'port'				 - to listen on a TCP socket to all addresses
;							(IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
;				 mode is set to 0660
listen.owner = www
listen.group = www
;listen.mode = 0660

 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
Argh -- reaching out here --- Intentions were to write a tutorial on how to use 2Factor Authentication via use of the PrivacyIdea App https://github.com/NetKnights-GmbH/privacyidea-owncloud-app/tree/master/twofactor_privacyidea and the PrivacyIdea Modular Application App http://privacyidea.readthedocs.io/en/latest/index.html. I got the Modular Application App up and running with great difficulty and installed the plugin within Owncloud however I never got the owncloud plugin to authenticate, although I could manually authenticate through the app. 2Factor authentication app installed on the mobile phone as well. ...Argh.....After thorough frustration -- anyone else able to make this a go?

Just ended up installing TOFT https://apps.owncloud.com/content/show.php?content=174726&forumpage=0. Works pretty good for two factor and setup about 10 times easier
 
Last edited:

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
I re ran the pkg install code and it fixed the server it's working again. Don't understand what broke.
pkg install nginx mariadb101-server redis php70-bz2 php70-ctype php70-curl php70-dom php70-exif php70-fileinfo php70-filter php70-gd php70-hash php70-iconv php70-intl php70-json php70-mbstring php70-mcrypt php70-pdo_mysql php70-openssl php70-posix php70-session php70-simplexml php70-xml php70-xmlreader php70-xmlwriter php70-xsl php70-wddx php70-zip php70-zlib php70-APCu php70-redis
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I re ran the pkg install code and it fixed the server it's working again. Don't understand what broke.
pkg install nginx mariadb101-server redis php70-bz2 php70-ctype php70-curl php70-dom php70-exif php70-fileinfo php70-filter php70-gd php70-hash php70-iconv php70-intl php70-json php70-mbstring php70-mcrypt php70-pdo_mysql php70-openssl php70-posix php70-session php70-simplexml php70-xml php70-xmlreader php70-xmlwriter php70-xsl php70-wddx php70-zip php70-zlib php70-APCu php70-redis
php versions 5.6 and below don't use the www.conf, so if you somehow installed older php it would have ignored your settings.
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
After having some problems with OwnCloud and the extensions, I was tipped off on github by one of the developers of the extensions, that most have dropped their support or no longer supporting OwnCloud and have switched to NextCloud. The process of switching over from owncloud to nextcloud is rather painless. I'll include my ngnix.conf file if anyone is interested. I additionally just needed to make a new table within MariaDB for nextcloud rather than owncloud. It's possible possible, but probably not practical to run the installations side by side accessing the same storage. Since the SSL certificate was enabled for the domain, this setup didn't change. After seeing the enhancements offered by nextcloud 11 compared to owncloud 9, I'm wondering when/if FreeNAS will officially switch support??
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
After having some problems with OwnCloud and the extensions, I was tipped off on github by one of the developers of the extensions, that most have dropped their support or no longer supporting OwnCloud and have switched to NextCloud. The process of switching over from owncloud to nextcloud is rather painless. I'll include my ngnix.conf file if anyone is interested. I additionally just needed to make a new table within MariaDB for nextcloud rather than owncloud. It's possible possible, but probably not practical to run the installations side by side accessing the same storage. Since the SSL certificate was enabled for the domain, this setup didn't change. After seeing the enhancements offered by nextcloud 11 compared to owncloud 9, I'm wondering when/if FreeNAS will officially switch support??
The nginx config for owncloud documented here works fine for nextcloud; what does your nginx.conf change that people would need it? I am the person who wrote most of the nginx documentation for owncloud/nextcloud so I should know if something is needed.

I do not understand what you mean by "officially switch support"? There are official FreeNAS plugins for both owncloud and nextcloud.
This thread is not related to the official plugins; it is an unofficial guide for installing them manually.
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
INTRODUCTION
This guide's purpose is to show my recommended method to install ownCloud in a jail on FreeNAS. This method will have superior performance over the PBI method because this stack uses NGINX, PHP-FPM, and MySQL instead of Apache (with Mod-PHP) and SQLite.

INSTALLATION

OPTIONAL CONFIGURATION

Thank you so much for the tutorial.
I followed everything to the letter and did not get any errors along the way (that I know of) but I still cannot get NGINX to process .PHP files.
I even created a test.php with phpinfo inside it.
When I point my incognito browser to the test.php file it says "No input file specified."
I did
Code:
 service nginx restart
and it all starts fine:

Code:
root@nextcloud_1:/ # service nginx restart																						 
Performing sanity check on nginx configuration:																					 
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok														 
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful														
Stopping nginx.																													 
Waiting for PIDS: 89587.																											
Performing sanity check on nginx configuration:																					 
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok														 
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful														
Starting nginx.																													 
root@nextcloud_1:/ #	 

Any help please, I have been trying to get this working for the past two days, and I hate to bother other people for help but I'm out of ideas. Thanks
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Thank you so much for the tutorial.
I followed everything to the letter and did not get any errors along the way (that I know of) but I still cannot get NGINX to process .PHP files.
I even created a test.php with phpinfo inside it.
When I point my incognito browser to the test.php file it says "No input file specified."
I did
Code:
 service nginx restart
and it all starts fine:

Code:
root@nextcloud_1:/ # service nginx restart																						
Performing sanity check on nginx configuration:																					
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok														
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful														
Stopping nginx.																													
Waiting for PIDS: 89587.																											
Performing sanity check on nginx configuration:																					
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok														
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful														
Starting nginx.																													
root@nextcloud_1:/ #	

Any help please, I have been trying to get this working for the past two days, and I hate to bother other people for help but I'm out of ideas. Thanks
Actually ever since owncloud 9, the documented configuration will not open PHP files unless they are explicitly in that list. But that probably isn't your issue.

As you guess, it probably is an issue with your nginx config. test.php should have been processed by nginx to run index.php. I would check for any mistakes in your config. Maybe a screenshot to verify your config would be helpful.

EDIT
Ohh, and you did try http://jail_IP/owncloud right?
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
Actually ever since owncloud 9, the documented configuration will not open PHP files unless they are explicitly in that list. But that probably isn't your issue.

As you guess, it probably is an issue with your nginx config. test.php should have been processed by nginx to run index.php. I would check for any mistakes in your config. Maybe a screenshot to verify your config would be helpful.

EDIT
Ohh, and you did try http://jail_IP/owncloud right?
Hi, yes the url is like you said (only nextcloud). http://jail_IP/nextcloud

Conf file:
Code:
load_module /usr/local/libexec/nginx/ngx_mail_module.so;						
load_module /usr/local/libexec/nginx/ngx_stream_module.so;					
																			 
																			 
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 ^~ /nextcloud {												
			client_max_body_size 512M;										
			error_page 403 /nextcloud/core/templates/403.php;				
			error_page 404 /nextcloud/core/templates/404.php;				
			location /nextcloud {											
				rewrite ^ /nextcloud/index.php$uri;							
			}																
			location ~^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|d
ata)/ {																		
				deny all;													
			}																
			location ~^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) {
				deny all;													
			}																
			location ~^/nextcloud/(?:index|remote|public|cron|core/ajax/update|s
tatus|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 ~* \.(?:css|js)$ {										
				try_files $uri /nextcloud/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 /nextcloud/index.php$uri$is_args$args;		
			}																
																			 
		}																	
	}																		
}																			


This is how my dir/ls looks like
Code:
root@nextcloud_1:/usr/local/www # ls											
nextcloud	   nginx		   nginx-dist	  test.php  


and this is dir/ls for www/nginx
Code:
root@nextcloud_1:/usr/local/www/nginx # ls									 
50x.html																		
EXAMPLE_DIRECTORY-DONT_ADD_OR_TOUCH_ANYTHING									
index.html																	 
test.php																		
root@nextcloud_1:/usr/local/www/nginx #
 
Last edited:

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Hi, yes the url is like you said (only nextcloud). http://jail_IP/nextcloud

Conf file:
Code:
load_module /usr/local/libexec/nginx/ngx_mail_module.so;						
load_module /usr/local/libexec/nginx/ngx_stream_module.so;					 
																			  
																			  
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 ^~ /nextcloud {												
			client_max_body_size 512M;										 
			error_page 403 /nextcloud/core/templates/403.php;				 
			error_page 404 /nextcloud/core/templates/404.php;				 
			location /nextcloud {											 
				rewrite ^ /nextcloud/index.php$uri;							
			}																 
			location ~^/nextcloud/(?:build|tests|config|lib|3rdparty|templates|d
ata)/ {																		
				deny all;													 
			}																 
			location ~^/nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) {
				deny all;													 
			}																 
			location ~^/nextcloud/(?:index|remote|public|cron|core/ajax/update|s
tatus|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 ~* \.(?:css|js)$ {										
				try_files $uri /nextcloud/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 /nextcloud/index.php$uri$is_args$args;		 
			}																 
																			  
		}																	 
	}																		 
}																			 
do your files actually exist at /usr/local/www/nextcloud?
 
Top