Re: php-fpm unable to connect to active socket - solution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2018-09-10 at 14:31 -0400, John wrote:
> From: John <john.iliffe@xxxxxxxxx>
> Reply-to: john.iliffe@xxxxxxxxx
> To: PHP List <php-general@xxxxxxxxxxxxx>
> Subject: php-fpm unable to connect to active socket - update
> Date: Sun, 09 Sep 2018 00:07:14 -0400
> 
> > I changed from PHP 5.6.30 to PHP 7.2.9 and now I am unable to run scripts
> > that
> > access pgsql using socket 5432.  The old PHP 5.6.30 works as expected.
> > 
> > The configuration is apache using php-fpm to execute the PHP
> > scripts.  scripts
> > that use PHP but do not connect to the database seem to work OK but haven't
> > been
> > fully tested yet.  
> > 
> > php-fpm is started using the systemd script included with the download. 
> > Formerly PHP 5.6.30 was started as an init.d script.
> > 
> > Error message is:
> > 
> > ---------------
> > Warning: pg_connect(): Unable to connect to PostgreSQL server: could not
> > connect
> > to server: No such file or directory Is the server running locally and
> > accepting
> > connections on Unix domain socket "/tmp/.s.PGSQL.5432"? 
> > ---------------
> > 
> > ls -a /tmp/.s.*
> > /tmp/.s.PGSQL.5432 
> > 
> > ss -a | grep 5432
> > u_str  LISTEN     0      128    /tmp/.s.PGSQL.5432 29050                 *
> > 0   
> > 
> > Restarting PHP 5.6.30 immediately reconnects to socket 5432 as always and
> > all
> > scripts calling the database work as expected.  I have stopped and started
> > both
> > versions of PHP multiple times, and also pgsql, so it doesn't appear to be a
> > lock on the socket from PHP 5.6.30 causing the problem.
> > 
> > The configure parameters to make are (taken from php_info):
> > 
> > './configure' '--prefix=/usr/php-7.2.9' '--with-apxs2=/usr/apache-
> > 2.4.25/bin/apxs' '--enable-fpm' '--with-fpm-user=phpfpm' '--with-fpm-
> > group=phpfpm' '--with-fpm-systemd' '--disable-short-tags' '--with-
> > openssl=/usr/openssl-1.1.0i' '--with-zlib' '--with-pgsql=/usr/postgres-
> > 9.6.2'
> > '-
> > -with-pear' '--with-libxml-dir=/usr/lib64' 
> > 
> > Can anyone see anything that might be causing this?  Or suggest some way to
> > try
> > and debug it?
> > 
> > Thanks in advance.
> > 
> > John
> 
> =====================================
> I have been trying to resolve this issue and I have some addition information
> now:
> 
> 1.	CLI invocation of these scripts works as expected; only php-fpm
> fails
> 
> 2.	php-fpm is issuing an error message about not being able to reach
> the
> Unix domain socket on 5432; I think this should be a TCP socket 5432.
> 
> [10-Sep-2018 13:48:46] WARNING: [pool xxxx] child 15848 said into stderr:
> "NOTICE: PHP message: PHP Warning:  pg_connect(): 
> Unable to connect to PostgreSQL server: could not connect to server: No such
> file or directory"
> [10-Sep-2018 13:48:46] WARNING: [pool xxxx] child 15848 said into stderr:
> "     Is the server running locally and accepting"
> [10-Sep-2018 13:48:46] WARNING: [pool xxxx] child 15848 said into stderr:
> "     connections on Unix domain socket 
>       &quot;/tmp/.s.PGSQL.5432&quot;? in /httpd/xxxx/dm0002.php on line 202"
> 
> Here is line 202 of that script:
> 
>    $db_handle = pg_connect('dbname=xxxxxxx user=uuuuuu password=yyyyyyyy');
> 
> I'm not at all sure why pg_connect() would be trying to reach a Unix domain
> socket from php-fpm and a TCP socket from php CLI.  
> 
> For completeness, here is another line from ss -a that may apply:
> 
>   tcp    LISTEN     0      128    127.0.0.1:postgres              *:*
> 
> I checked the PHP-5 to PHP-7 migration information and there is nothing
> regarding socket type changes between them in the documentation.  I also
> checked
> the online manual and while I can see how to force a domain socket I can't see
> anything about going the other way.  
> 
> This looks like a configuration error but I can't find any parameter in either
> php.ini or php-fpm.conf that applies.
> 
> Any suggestions?
> 
> John
> ============================================
I finally got this resolved, not where I would have expected!

The problem was in the systemd service file provided with php-fpm.  The
parameter PrivateTmp is set to true.  Unfortunately, that masks the real /tmp
directory which is where the socket file for pgsql is located.  Since I can't
change that location without breaking everything else that uses pgsql, a lot of
things on this server, I set PrivateTmp to false and everything works as it
should.

This may be a security issue, although if so it has existed for a long time, but
even so it would be nice if the documentation mentioned it somewhere.  At least
one would know where to begin to search for an answer.

John
========================================================




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux