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

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
do your files actually exist at /usr/local/www/nextcloud?
Hi, Yes.
Code:
root@nextcloud_1:/usr/local/www/nextcloud # ls								 
.htaccess			   db_structure.xml		remote.php					 
.user.ini			   index.html			  resources					   
3rdparty				index.php			   robots.txt					 
AUTHORS				 l10n					settings						
apps					lib					 status.php					 
config				  occ					 themes						 
console.php			 ocs					 updater						 
core					ocs-provider			version.php					 
cron.php				public.php											 
root@nextcloud_1:/usr/local/www/nextcloud #	 
 

KevDog

Patron
Joined
Nov 26, 2016
Messages
462
No expert here but aren't you missing a location block in your nginx config file which begins similar to
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php-fpm:
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

Just a guess
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
No expert here but aren't you missing a location block in your nginx config file which begins similar to
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php-fpm:
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

Just a guess
Hi, I added your code just to be sure but still the same issue.
I also looked in /var/run/php-fpm.sock but I don't a php-fpm.sock file there. Can this be the problem ?
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Is there an extra return space in your config file or did the formatting carry the semicolon over to the next line?

Code:
			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 <-It should be here*********
;  <-This one right here************************																	
				fastcgi_param PATH_INFO $fastcgi_path_info;					
				fastcgi_param front_controller_active true;					
				fastcgi_intercept_errors on;


Also you can remove that code you just added, the location block above processes php.
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
Is there an extra return space in your config file or did the formatting carry the semicolon over to the next line?

Code:
			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 <-It should be here*********
;  <-This one right here************************																	
				fastcgi_param PATH_INFO $fastcgi_path_info;					
				fastcgi_param front_controller_active true;					
				fastcgi_intercept_errors on;


Also you can remove that code you just added, the location block above processes php.
Hi,
the semicolon carried over (its all on one line).
I removed the code I just added.
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Is there a space between fastcgi_script_name and the semicolon?
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
Is there a space between fastcgi_script_name and the semicolon?
Hi, no
Code:
				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;				 
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
No expert here but aren't you missing a location block in your nginx config file which begins similar to
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php-fpm:
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

Just a guess
If you see the beginning of the thread and the nextcloud documentation the location matching has changed to not match every php file anymore.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Hi, Yes.
Code:
root@nextcloud_1:/usr/local/www/nextcloud # ls								
.htaccess			   db_structure.xml		remote.php					
.user.ini			   index.html			  resources					  
3rdparty				index.php			   robots.txt					
AUTHORS				 l10n					settings						
apps					lib					 status.php					
config				  occ					 themes						
console.php			 ocs					 updater						
core					ocs-provider			version.php					
cron.php				public.php											
root@nextcloud_1:/usr/local/www/nextcloud #	
What do you get when you browse to the following URLs
/nextcloud/index.php
/nextcloud/robots.txt
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
What do you get when you browse to the following URLs
/nextcloud/index.php
/nextcloud/robots.txt
For: nextcloud/index.php
I get:
Code:
502 Bad Gateway
nginx/1.10.2


For: nextcloud/robots.txt
I get:
Code:
User-agent: *
Disallow: /


and if I try the test.php file that I created that has the phpinfo (that is outside of nextcloud's dir, in the main www and also one in the
/usr/local/www/nginx dir) I get a download dialog to download that file (the file is always empty once downloaded and opened).
 
Last edited:

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
For: nextcloud/index.php
I get:
Code:
502 Bad Gateway
nginx/1.10.2


For: nextcloud/robots.txt
I get:
Code:
User-agent: *
Disallow: /


and if I try the test.php file that I created that has the phpinfo I get a download dialog to download that file.
As I explained earlier, any php files, other than those defined in the nginx config will not work.

Is your php socket listening at /var/run/php-fpm.sock? please check 'sockstat'
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
As I explained earlier, any php files, other than those defined in the nginx config will not work.

Is your php socket listening at /var/run/php-fpm.sock? please check 'sockstat'
Code:
root@nextcloud_1:/usr/local/www/nginx # sockstat -l																				
USER	 COMMAND	PID   FD PROTO  LOCAL ADDRESS		 FOREIGN ADDRESS														 
www	  nginx	  96528 7  tcp4   *:80				  *:*																	 
www	  nginx	  96527 7  tcp4   *:80				  *:*																	 
root	 nginx	  96526 7  tcp4   *:80				  *:*																	 
mysql	mysqld	 91945 20 stream /tmp/mysql.sock																				
www	  php-fpm	91837 0  tcp4   127.0.0.1:9000		*:*																	 
www	  php-fpm	91836 0  tcp4   127.0.0.1:9000		*:*																	 
root	 php-fpm	91835 10 tcp4   127.0.0.1:9000		*:*																	 
redis	redis-serv 91831 4  stream /tmp/redis.sock																				
root	 syslogd	91775 4  dgram  /var/run/log																					
root	 syslogd	91775 5  dgram  /var/run/logpriv																				
root	 syslogd	91775 6  udp6   *:514				 *:*																	 
root	 syslogd	91775 7  udp4   *:514				 *:*																	 
root@nextcloud_1:/usr/local/www/nginx #																							
															 

I don't see it or the file in /var/run.
This is what is in /var/run/
Code:
root@nextcloud_1:/var/run # ls																									
clean_var			   ld-elf32.so.hints	   nginx.pid			   redis				   utx.active						
cron.pid				log					 php-fpm.pid			 syslog.pid			  wpa_supplicant					
ld-elf.so.hints		 logpriv				 ppp					 syslogd.sockets											
root@nextcloud_1:/var/run #																										
								 
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Code:
www	  php-fpm	91837 0  tcp4   127.0.0.1:9000		*:*																	  
www	  php-fpm	91836 0  tcp4   127.0.0.1:9000		*:*																	  
root	 php-fpm	91835 10 tcp4   127.0.0.1:9000		*:*


There's your problem. Go back to the first page of this thread and make the changes to your www.conf file.

ETA: And thank @Joshua Parker Ruehlig for figuring it out and writing this awesome tutorial.
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
Code:
www	  php-fpm	91837 0  tcp4   127.0.0.1:9000		*:*																	 
www	  php-fpm	91836 0  tcp4   127.0.0.1:9000		*:*																	 
root	 php-fpm	91835 10 tcp4   127.0.0.1:9000		*:*


There's your problem. Go back to the first page of this thread and make the changes to your www.conf file.

ETA: And thank @Joshua Parker Ruehlig for figuring it out and writing this awesome tutorial.
I made changes but it still doesn't work. Can you please see what I am doing wrong in www.conf ?
# vi /usr/local/etc/php-fpm.d/www.conf
Code:
; Default Value: none																											  
;prefix = /path/to/pools/$pool																									  
																																   
; Unix user/group of processes																									  
; Note: The user is mandatory. If the group is not set, the default user's group													
;	   will be used.																											  
user = www																														  
group = www																														
																																   
; 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 = 127.0.0.1:9000																											
; 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.mode = 0660																												  
																																   
;NEW TEST INSERT START																											  
listen = /var/run/php-fpm.sock																									  
listen.owner = www																												  
listen.group = www																												  
env[PATH] = /usr/local/bin:/usr/bin:/bin																							
;NEW TEST INSERT END																												
																																   
; When POSIX Access Control Lists are supported you can set them using															  
; these options, value is a comma separated list of user/group names.															  
; When set, listen.owner and listen.group are ignored																			  
;listen.acl_users =																												
;listen.acl_groups =																												
																																   
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.													
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original													  
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address		  
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I made changes but it still doesn't work. Can you please see what I am doing wrong in www.conf ?
# vi /usr/local/etc/php-fpm.d/www.conf
Code:
; Default Value: none																											 
;prefix = /path/to/pools/$pool																									 
																																  
; Unix user/group of processes																									 
; Note: The user is mandatory. If the group is not set, the default user's group													
;	   will be used.																											 
user = www																														 
group = www																														
																																  
; 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 = 127.0.0.1:9000																											
; 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.mode = 0660																												 
																																  
;NEW TEST INSERT START																											 
listen = /var/run/php-fpm.sock																									 
listen.owner = www																												 
listen.group = www																												 
env[PATH] = /usr/local/bin:/usr/bin:/bin																							
;NEW TEST INSERT END																												
																																  
; When POSIX Access Control Lists are supported you can set them using															 
; these options, value is a comma separated list of user/group names.															 
; When set, listen.owner and listen.group are ignored																			 
;listen.acl_users =																												
;listen.acl_groups =																												
																																  
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.													
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original													 
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address		 
did you restart php after making the changes? 'service php-fpm restart'
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
Ahh, now I cannot pass the setup screen.
I guess the login info is not correct ?
I thought I entered ocuser and ocpass at setup but maybe I didn't.

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000][1045] Access denied for user 'ocuser@localhost' (using password: YES)

Is there anyway to reset it ?
for do I have to reinstall ?

Thanks again
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Ahh, now I cannot pass the setup screen.
I guess the login info is not correct ?
I thought I entered ocuser and ocpass at setup but maybe I didn't.

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000][1045] Access denied for user 'ocuser@localhost' (using password: YES)

Is there anyway to reset it ?
for do I have to reinstall ?

Thanks again
REINSTALL FROM SCRATCH!!!!!!!!
Lol, just kidding.

just log into mysql using your root password (if you set one with mysql_secure_installation). and run the SQL commands

mysql -u root -p
DROP DATABASE owncloud;
CREATE DATABASE owncloud;
GRANT ALL PRIVILEGES ON owncloud.* TO 'ocuser'@'localhost' IDENTIFIED BY 'ocpass';
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
REINSTALL FROM SCRATCH!!!!!!!!
Lol, just kidding.

just log into mysql using your root password (if you set one with mysql_secure_installation). and run the SQL commands

mysql -u root -p
DROP DATABASE owncloud;
CREATE DATABASE owncloud;
GRANT ALL PRIVILEGES ON owncloud.* TO 'ocuser'@'localhost' IDENTIFIED BY 'ocpass';

Thanks again for everything. (your amazing)
 

msvuze

Dabbler
Joined
Dec 11, 2016
Messages
45
I restarted Freenas just to make sure it nextcloud would work again, and to my surprise when I went to the URL is says:
Code:
502 Bad Gateway
nginx/1.10.2


so I went into the jail shell and did the following:
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: 33869.																											
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:/ # sockstat -l																									
USER	 COMMAND	PID   FD PROTO  LOCAL ADDRESS		 FOREIGN ADDRESS														 
www	  nginx	  34005 7  tcp4   *:80				  *:*																	 
www	  nginx	  34004 7  tcp4   *:80				  *:*																	 
root	 nginx	  34003 7  tcp4   *:80				  *:*																	 
mysql	mysqld	 33091 70 stream /tmp/mysql.sock																				
www	  php-fpm	32983 0  tcp4   127.0.0.1:9000		*:*																	 
www	  php-fpm	32982 0  tcp4   127.0.0.1:9000		*:*																	 
root	 php-fpm	32981 7  tcp4   127.0.0.1:9000		*:*																	 
redis	redis-serv 32977 4  stream /tmp/redis.sock																				
root	 syslogd	32916 4  dgram  /var/run/log																					
root	 syslogd	32916 5  dgram  /var/run/logpriv																				
root	 syslogd	32916 6  udp6   *:514				 *:*																	 
root	 syslogd	32916 7  udp4   *:514				 *:*																	 
root@nextcloud_1:/ #											 



I checked the nginx.conf and www.conf files and they look the same like I left them before the restart.
What can it be now ?
 
Top