Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
php-fpm socket + nginx
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Wed Mar 06, 2013 5:44 pm    Post subject: php-fpm socket + nginx Reply with quote

Hi,

I'm trying to host my own Friendica http://friendica.com/ site using the following:


  • www-servers/nginx-1.2.6-r1
  • dev-db/mariadb-5.5.29
  • dev-lang/php-5.4.8 with fpm


I've followed these guides:


I'm trying to use a unix socket instead of tcp for connecting to the fastcgi fpm, but my socket doesn't seem to get created so I'm getting a "502 Bad Gateway" error message.
Code:

# grep unix /etc/nginx/sites-available/fd.conf
      fastcgi_pass unix:/var/run/php5-fpm/fd.socket;

# grep pool\.d /etc/php/fpm-php5.4/php-fpm.conf
include = /etc/php/fpm-php5.4/pool.d/*.conf


And my socket definition file:
/etc/php/fpm-php5.4/pool.d/fd.conf
Code:

listen = /var/run/php5-fpm/fd.socket
listen.backlog = -1

; Unix user/group of processes
user  = nginx
group = nginx

; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

; host-specific php ini settings here
; php_admin_value[open_basedir] = /var/www/DOMAINNAME/htdocs:/tmp


My fpm log shows nothing helpful:
Code:

[06-Mar-2013 12:34:19] WARNING: [pool www] pm.start_servers is not set. It's been set to 20.
[06-Mar-2013 12:34:19] NOTICE: fpm is running, pid 12163
[06-Mar-2013 12:34:19] NOTICE: ready to handle connections



Anybody know how to configure fpm to create socket?
Thanks.
Back to top
View user's profile Send private message
i-s-a-k
n00b
n00b


Joined: 05 Dec 2006
Posts: 18

PostPosted: Wed Mar 06, 2013 6:26 pm    Post subject: Reply with quote

Have you confirmed that the socket is actually created?

file /var/run/php5-fpm/fd.socket

Should return

/var/run/php5-fpm/fd.socket: socket
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Wed Mar 06, 2013 7:17 pm    Post subject: Reply with quote

I manually created the directory /var/run/php5-fpm/
but it's empty.

The socket file /var/run/php5-fpm/fd.socket never never gets created.

When I start /etc/init.d/php-fpm
it's supposed to create the pool of sockets, right?

as specified in /etc/php/fpm-php5.4/php-fpm.conf ?

The Gentoo wiki used the tcp connection, but recommended sockets.
The rackspace setup guide said to put a socket configuration file in the pool directory:

Quote:

To complete the setup move to the directory /etc/php5/fpm/pool.d/.
It is here that you will setup the different UNIX Sockets that PHP-FPM will function on.

Please Note: In order for your system to function properly you will need to create a new POOL for every Virtual Host that you had setup.

The pool files should follow this naming convention: YOURDOMAIN.conf

Here is a template for the pool files.


So I created /etc/php/fpm-php5.4/pool.d
and added a template pool file to it, chaning the DOMAINNAME, etc.

Then I added line the the php-fpm.conf to include the pool config file,
but the rackspace guide didn't specify what how that line looked
(I guess it's part of their default setup but not Gentoo's)
Back to top
View user's profile Send private message
i-s-a-k
n00b
n00b


Joined: 05 Dec 2006
Posts: 18

PostPosted: Wed Mar 06, 2013 8:38 pm    Post subject: Reply with quote

And you've made sure that the nginx user has write access to /var/run/php5-fpm/ ?
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Wed Mar 06, 2013 9:01 pm    Post subject: Reply with quote

# ls -ldn /var/run
drwxr-xr-x 20 0 0 4096 Mar 6 15:36 /var/run

# ls -ldn /var/run/php5-fpm/
drwxr-xr-x 2 124 978 4096 Mar 5 22:28 /var/run/php5-fpm/

# id nginx
uid=124(nginx) gid=978(nginx) groups=978(nginx)
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Wed Mar 06, 2013 11:39 pm    Post subject: Reply with quote

Hmmm, there's one WARNING from php-fpm about pm.start_server not being set:

# cat /var/log/php-fpm.log
Code:

[06-Mar-2013 18:31:09] NOTICE: Finishing ...
[06-Mar-2013 18:31:09] NOTICE: exiting, bye-bye!
[06-Mar-2013 18:31:09] WARNING: [pool www] pm.start_servers is not set. It's been set to 20.
[06-Mar-2013 18:31:09] NOTICE: fpm is running, pid 17943
[06-Mar-2013 18:31:09] NOTICE: ready to handle connections



But I've included /etc/php/fpm-php5.4/pool.d/*.conf

# grep -v '^;' php-fpm.conf |grep -v '^$'
Code:

[global]
error_log = /var/log/php-fpm.log
[www]
include=/etc/php/fpm-php5.4/pool.d/*.conf
 
user = nobody
group = nobody
pm = dynamic
pm.max_children = 50
pm.min_spare_servers = 5
pm.max_spare_servers = 35



And fd.conf should set pm.start_servers = 10


# grep -v '^;' pool.d/fd.conf |grep -v '^$'
Code:

listen = /var/run/php5-fpm/fd.sock
listen.backlog = -1
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
user  = nginx
group = nginx
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Back to top
View user's profile Send private message
i-s-a-k
n00b
n00b


Joined: 05 Dec 2006
Posts: 18

PostPosted: Thu Mar 07, 2013 3:25 am    Post subject: Reply with quote

[www]
include=/etc/php/fpm-php5.4/pool.d/*.conf

seems like you are setting the poolname [www] before the include

that might be ok if you have only 1 pool, but if you have multiple pools that will cause some problems
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Thu Mar 07, 2013 2:15 pm    Post subject: Reply with quote

OK, I tried moving "include" line to just before pool definition section in php-fpm.conf
Same result -- no socket created.

I've also checked out the configuration wiki
http://php-fpm.org/wiki/Configuration_File

but it's not very helpful.


/etc/init.d/php-fpm seems to start daemon as ""root and worker processes as "nobody":
Code:

root 5215  1  0 08:57 ?  00:00:00 php-fpm: master process (/etc/php/fpm-php5. /php-fpm.conf)                                 
nobody    5216  5215  0 08:57 ?        00:00:00 php-fpm: pool www


I've tried changing ownership/group/permissions in php-fpm.conf and in pool.d/fd.conf:
Code:

listen.owner = nginx
listen.group = nginx
listen.mode = 0666


but master and workers still run as root and nobody.

And php-fpm still warns about pm.start_server not being set:
Code:

# cat /var/log/php-fpm.log
[07-Mar-2013 08:57:46] WARNING: [pool www] pm.start_servers is not set. It's been set to 20.
[07-Mar-2013 08:57:46] NOTICE: fpm is running, pid 5215
[07-Mar-2013 08:57:46] NOTICE: ready to handle connections


even though it is (I think):
# grep pm.start_servers pool.d/fd.conf
Code:

pool.d/fd.conf:pm.start_servers = 10


I've tried setting it in main php-fpm.conf as well and the log still complains about it not being set and then setting it to a default value of 20.


I wonder if any Gentoo users have got php-fpm working with sockets or if there's something goofy with Gentoo's init script?
I guess I can switch from sockets to tcp data connection if I can't figure out how to get this working.
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Thu Mar 07, 2013 3:44 pm    Post subject: [SOLVED] fpm socket file created! Reply with quote

Well,

I've been modifying the config files for php5.4-fpm
but apparently using php5.3

so I need to tell Gentoo to change PHPSLOT for fpm's init script to 5.4:

http://www.gentoo.org/proj/en/php/php-upgrading.xml

Code:

# eselect php list fpm
  [1]   php5.3 *
  [2]   php5.4
# eselect php set fpm 2
# eselect php list fpm
  [1]   php5.3
  [2]   php5.4 *


Now, finally, it creates socket file:
Code:

# ls -l /var/run/php5-fpm/
total 0
srw-rw-rw- 1 nginx nginx 0 Mar  7 10:30 fd.sock


My working config files:
# grep -v '^;' php-fpm.conf |grep -v '^$'
Code:

[global]
error_log = /var/log/php-fpm.log
[www]
include=/etc/php/fpm-php5.4/pool.d/*.conf
 
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
user = nobody
group = nobody
pm = dynamic
pm.max_children = 50
pm.min_spare_servers = 5
pm.max_spare_servers = 35


# grep -v '^;' pool.d/fd.conf |grep -v '^$'
Code:

listen = /var/run/php5-fpm/fd.sock
listen.backlog = -1
user  = nginx
group = nginx
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp


Also, FWIW, the include statement must come under the pool [www] section.
If I put it anywhere before the pool section then I get the following error:
Code:

# /etc/init.d/php-fpm start
 * Starting PHP FastCGI Process Manager ...
[07-Mar-2013 10:36:30] ERROR: [/etc/php/fpm-php5.4/pool.d/social.conf:1] unknown entry 'listen'
[07-Mar-2013 10:36:30] ERROR: Unable to include /etc/php/fpm-php5.4/pool.d/social.conf from /etc/php/fpm-php5.4/php-fpm.conf at line 1
[07-Mar-2013 10:36:30] ERROR: failed to load configuration file '/etc/php/fpm-php5.4/php-fpm.conf'
[07-Mar-2013 10:36:30] ERROR: FPM initialization failed
 * start-stop-daemon: failed to start `/usr/lib/php5.4/bin/php-fpm'
^C * php-fpm: caught SIGINT, aborting
Back to top
View user's profile Send private message
i-s-a-k
n00b
n00b


Joined: 05 Dec 2006
Posts: 18

PostPosted: Thu Mar 07, 2013 9:49 pm    Post subject: Reply with quote

my point was not to move the include line

it was that [www] is the name of the pool, so if you have multiple pools

then you should include that inside the included files

for example


cat /etc/php/fpm-php5.4/pools/www.pool.conf
[www]
listen = /var/run/www_fpm.sock
pm = dynamic
pm.start_servers = 1
.... etc


cat /etc/php/fpm-php5.4/pools/www2.pool.conf
[www2]
listen = /var/run/www2_fpm.sock
pm = dynamic
pm.start_servers = 1
.... etc



anyway good that you got it working :)
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Thu Mar 07, 2013 10:08 pm    Post subject: Reply with quote

Thanks for the help!


I've got a regular LAMP server on another machine.
I was going to setup mariadb+nginx in an lxc container
but I think my kernel (3.3.8) is too new for lxc
lxc-start kept complaining about a missing kernel option
that's been removed from the current kernel's makefile.

So I'm just setting this up on main host.

Haven't yet got Friendica working.
Just getting a blank screen which probably means there some missing php module
that I haven't yet tracked down.

Friendica supplies a virtualbox image but I was trying to see if I could just
install the webapp and the database
without running virtualbox.

Anybody hosting their own friendica?
Back to top
View user's profile Send private message
redwood
Guru
Guru


Joined: 27 Jan 2006
Posts: 306

PostPosted: Fri Mar 08, 2013 5:34 pm    Post subject: Reply with quote

Fixed my blank screen issue.

Somehow I deleted or didn't cut-n-paste the first line
of /etc/nginx/fastcgi_params:

which should have been:

Quote:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


Now php is working.

nginx is running as user 'nginx'
and fpm-php is running as 'root' and workers are running as 'nobody'

And I 'chown -R nginx.nginx /var/www/fd/'
but Friendica installer complained it couldn't write to /var/www/fd/htdocs/fd'
so I had to 'chmod o+w /var/www/fd.mydomain.com/htdocs/fd'

Quote:

stat --format '%a' /var/www/fd.mydomain.com/htdocs/fd/
755


Only complain Friendica has now is that it requires mysqli php module.
Back to top
View user's profile Send private message
dappiu
Apprentice
Apprentice


Joined: 14 Mar 2005
Posts: 242
Location: Pisa, Italy

PostPosted: Sat Apr 27, 2013 5:10 pm    Post subject: Reply with quote

redwood wrote:
Fixed my blank screen issue.

Somehow I deleted or didn't cut-n-paste the first line
of /etc/nginx/fastcgi_params:

which should have been:

Quote:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;




My ebuild installation of nginx provided 2 files: fastcgi_params and fastcgi.conf (qfile reports www-servers/nginx on both case)

fastcgi.conf includes the line you mentioned (fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;) but fastcgi_params do not!
So you could just include fastcgi.conf, or fastcgi_params but specifying the SCRIPT_FILENAME line.
I would not modify fastcgi_params adding that line, because someone could use it without expecting the SCRIPT_FILENAME argument.

Code:

location ~ \.php$ {
    include /etc/nginx/fastcgi.conf;
    fastcgi_pass ...
}


or

Code:

location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass ...
}

_________________
If the human brain were so simple that we could understand it, we would be so simple we couldn't.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum