php-fpm and unix socket support with mod_mpm_event.so

Issues related to applications and software problems
Post Reply
wilburunion
Posts: 22
Joined: 2017/01/05 14:55:14

php-fpm and unix socket support with mod_mpm_event.so

Post by wilburunion » 2017/10/24 22:22:04

Is there a known way to use UNIX SOCKETS and phpMyadmin with mod_mpm_event.so or mod_mpm_worker.so ?? I am using apache 2.4.28

I have it configured with mod_mpm_prefork.so through the main web server and it works under the Apache 2.0 Handler on php 7.0.24, and the virtual hosts work as php 5.6.31 under FPM/FastCGI, BUT if I configure FPM/FastCGI to the main server (www) >> phpMyAdmin will not work under 5.6.31 as FPM/FastCGI

When I change the config to FPM/FastCGI - everything thing else works but phpMyadmin - in other words it is not the php-fpm config

I have tried in the phpmyadmin.conf file

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi:///usr/share/phpmyadmin/$1
ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi:///usr/share/phpmyadmin$1index.php

and when configured for TCP

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1
ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin$1index.php

BUT - as far as i know - one cannot MIX a UNIX SOCKET config with a TCP config pool - which is what the rest of the server is configured for - eight other virtual hosts via UNIX SOCKETS.

And I tried a workaround as a pipe through TCP localhost as => unix:///run/php-fpm/server.sock|fcgi://127.0.0.1:9000/srv/http/ FROM => see https://bugs.launchpad.net/ubuntu/+sour ... ug/1324828

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1
ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi://127.0.0.1:9000/usr/share/phpmyadmin$1index.php

I did not try "localhost" in the place of 127.0.0.1:9000 - yet - which is supposed to "also" work as the word "localhost" with servers >= 2.4.10

There are a few solutions possibly here => https://serverfault.com/questions/45062 ... ypassmatch some with security issues and this one looks the most promising which requires Apache >= 2.4.10) - Inside the vhost in the httpd.conf file as modified below which would be:

# define a worker
<Proxy "unix:/var/run/php-fpm/server.sock|fcgi://localhost" retry=0>
ProxySet timeout=600
</Proxy>

<If "%{REQUEST_FILENAME} =~ /\.php$/ && -f %{REQUEST_FILENAME}">
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetHandler proxy:fcgi://localhost
</If>

I have not re-configure back to ALL php-fpm to try it yet

According to REMI at https://blog.remirepo.net/post/2012/04/ ... -HTTPD-2.4 and https://blog.remirepo.net/post/2014/03/ ... mprovement it can be done, "somehow"

I had to go back to mod_mpm_prefork.so as REMI states at viewtopic.php?t=50470 until this can be figured out

The page at https://stackoverflow.com/questions/231 ... -in-debian seems to indicate at least with TCP the order of the commands is important; but I do not find examples of the proxypassmatch directive used with UNIX SOCKETS ( https://httpd.apache.org/docs/2.4/mod/m ... ypassmatch ) so is there a known way to get phpMyadmin to work with php-fpm via UNIX SOCKETS ??

User avatar
remirepo
Posts: 447
Joined: 2014/09/21 09:07:12
Location: France
Contact:

Re: php-fpm and unix socket support with mod_mpm_event.so

Post by remirepo » 2017/10/25 03:56:03

The SetHandler way is far simpler than the ProxyPass
I don't have any issue running phpMyAdmin this way.

P.S. A long post will be published very soon about "switching to FPM" on https://developers.redhat.com/blog
Remi's Repository - Forum - Blog

wilburunion
Posts: 22
Joined: 2017/01/05 14:55:14

Re: php-fpm and unix socket support with mod_mpm_event.so

Post by wilburunion » 2017/10/25 17:03:39

Yes OK thanks Remi - however unless I am configuring wrong I am stuck with mod_mpm_prefork.so - because if I select either multi-threaded module mod_mpm_event.so or mod_mpm_worker.so - php does not work in the main server any longer and in configuring php-fpm - it configures under php 5.6.31 - the default through etc/php.ini and I cannot seem to get it configured under mod_mpm_event.so or mod_mpm_worker.so - to point through /etc/opt/remi/php70 so as to load php70 and I get text "unable to start session" etc

I looked on https://developers.redhat.com/blog but only found your "older" blogs from the year 2014 as to Running PHP FPM in Docker => https://developers.redhat.com/blog/2014 ... in-docker/ and Apache with various PHP versions, using SCL => https://developers.redhat.com/blog/2014 ... using-scl/ on how to use TCP to call multiple php versions, relevant to my issue, so i assume you have yet to post the new one you are referring to

But both those posts made me explore the /etc/opt/remi/php70/php-fpm.conf and /etc/opt/remi/php70/php-fpm.d/www.conf files a bit more closely and I "think" I can see how to call php70 via unix sockets for a single server through its pool config file now pointing the session to /etc/opt/remi/php70 with the php_admin_value and php_value directives by changing the /etc/httpd/conf.d/php70-php.conf into a limited hybrid of /etc/opt/remi/php70/php-fpm.conf to set the handler through the appropriate unix socket listening php-fpm conf file at /etc/php-fpm.d

Am I way off base here ??

That should get me php70 in that virtual host via php-fpm and then I can can deal with phpmyadmin again trying the revised "bug fix" version which is supposed to work as

ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi://localhost/usr/share/phpmyadmin/$1
ProxyPassMatch ^/phpmyadmin/(.*\.php(/.*)?)$ unix:/var/run/php-fpm/server.sock|fcgi://localhost/usr/share/phpmyadmin$1index.php

directives using "localhost" as a word instead of "127.0.0.1:9000" in the phpmyadmin conf file - with and without the "?" and / or "$" or "$1" as others have shown in a post I cannot seem to get back to right now - is an issue with the unix socket ProxyPassMatch directive in getting phpmyadmin to work

*** EDIT ***

I was all set to put the include statement at the bottom of the pool conf file as shown here => https://www.howtoforge.com/how-to-use-m ... centos-6.3 which should have worked for php70 - but then on restart of php-fpm - php 5.631 worked and launched phpMyadmin without the ProxyPassMatch statements and all i did was comment out some php_admin_value commands which were not loading and were throwing errors. Go figure . . .

*** EDIT ENDS ***

I will look for your post again later on https://developers.redhat.com/blog after it might have gotten posted in a few days


wilburunion
Posts: 22
Joined: 2017/01/05 14:55:14

Re: php-fpm and unix socket support with mod_mpm_event.so

Post by wilburunion » 2017/11/25 01:12:58

I am posting this hopefully assist others who come along - and it should be noted the "tcp" connection method does not apply here - and this is for centos 7 with rpm files install vis "yum" only from a repo - NOT compiled from source

I read the REMI red hat developer blog - above and it pointed me to many things in the right direction

My php-fpm setup is using the UNIX sockets approach and set handler - and I discovered by the example way that the ProxySet directive only works if you use ONE Proxyset directive with all the commands on one single line. I am running php-fpm in the mode "on demand" - and it makes a difference how many resources the server takes to launch and stay running vs "dynamic"

I searched the Apache site and the web to verify this but i found not definitive proof. Two sources tend to support the claim => https://www.magenx.com/magento-optimiza ... -per-vhost <= PLEASE NOTE THIS IS A cPanel example NOT APPLICABLE at all but to the line where they have => ProxySet timeout=7200 disablereuse=on <= all on the same line, and at https://httpd.apache.org/docs/2.4/mod/mod_proxy.html at the "Workers" section where Apache shows the example

<Proxy "http://backend.example.com">
ProxySet connectiontimeout=5 timeout=30
</Proxy>

(so see my http.conf snippet below where I have all the commands needed on one line)

Because i am running mpm_event AND Drupal 7 - a Content Management System - it was not getting the full request - because it was obvious not keeping the connection alive long enough to get it ALL. It would timeout on AJAX calls and SOAP call items and / or pages

The problem I was also having was thus the client was timing out - and returning a 408 error. It appears the server was closing the connection prematurely. See also https://serverfault.com/questions/42672 ... -side-of-t

Apache documents this a bit obscurely at https://httpd.apache.org/docs/2.4/mod/m ... meout.html where the document states for the
RequestReadTimeout Directive - the only directive for the module - "This directive can set various timeouts for receiving the request headers and the request body from the client. If the client fails to send headers or body within the configured time, a 408 REQUEST TIME OUT error is sent."

Because of how php-fpm and Drupal works, it will trip a timeout - so one has to BOTH extend the timeout (I doubled it over the default of 300 seconds) AND set the RequestReadTimeout to let Apache keep php-fpm alive as a Proxy AND extend time as it does if the header and body is large or the SSL issues result in a lag also. See again the Apache page for the mod_reqtimeout module

Additionally I have fcgi-spawn configured as a daemon pointed to as a fcgiwrapper through fcgiwrap in the fcgi.conf as =>
FcgidWrapper /usr/sbin/fcgiwrap .php

See https://www.howtoforge.com/perfect-serv ... spconfig-3 at SECTION 14 - "fcgiwrap" section ONLY as relevant - and also note there IS a fcgiwrap rpm in the el7 repo - unlike what that page claims. See https://centos.pkgs.org/7/ghettoforge-x ... 4.rpm.html

the serer was running sometimes fast sometimes slower depending on what drupal was trying to do - and the eCommerce pages in the Ubercart store to try to "checkout" where external calls are made to get live shipping quotes and pre=process the credit cards or get bitcoin amounts were timing out on 408 errors - and / or the only thing to make them work was hit the request button once and then as it was waiting hit it again.

This issue is not mentioned at this writing at https://developers.redhat.com/blog/2017 ... tion-tips/ either

This below is a snippet of my http.conf file and ssl.conf for ALL hosts (vhosts) duplicated with a new proxy name for the server from the server pool conf file at /etc/php-fpm.d directory

Timeout 600
RequestReadTimeout body=10,MinRate=1000
## REMI https://blog.remirepo.net/post/2014/03/ ... mprovement
# Proxy declaration
<Proxy "unix:/var/run/php-fpm/server.com.sock|fcgi://php-fpm">
# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time
ProxySet keepalive=On connectiontimeout=5 timeout=600 disablereuse=off
</Proxy>
# Redirect to the proxy
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/server.com.sock|fcgi://localhost"
</FilesMatch>
## REMI https://blog.remirepo.net/post/2014/03/ ... mprovement

It should also be noted that putting the Proxyset commands all on separate lines DOES NOT appear to work - nor does it produce any error it is not going to work. See especially the nuance issues at https://forum.remirepo.net/viewtopic.php?id=3240 Finally it should also be noted that the ProxyPass directive is not applicable at all in this example, and the simple placement of

SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

in the php.conf file ended all issues with phpMyadmin along with the timeout and RequestReadTimeout directives placed as above

Lastly I also have in the http.conf and ssl.conf files

FcgidMaxRequestLen 1073741824
FcgidIOTimeout 601

for all hosts also - though it not clear how much impact they have in a php-fpm setup

The site runs fast now and given how many issues nginx has with Drupal and according to others - using mpm_event - is as good as Apache gets. See for example http://www.eschrade.com/page/performanc ... -to-nginx/ and https://stackoverflow.com/questions/278 ... ing-poorly for an analysis of why mpm_event behaved this way closing my connections. There is no single explanation of this and one has to dig for truffles to figure it out

Post Reply