Performance and FastCGI - Very Good Results

Just wanted to share my experience trying to speed up the system by switching to using the fastCGI process manager on Apache 2.4 - specifically using mod_proxy_fcgi.

It wasn’t too difficult to get everything working. The main thing was to make sure the required php settings ended up in the right config file.

The speed increase was quite significant, however I’m still trying to get daily crons to run correctly. I think there’s a timeout somewhere that I must be missing - most likely proxy related. Once I figure out what’s going on, it shouldn’t be too hard to resolve.

In any case, if anyone is planning on going down this road, I think it can be worthwhile. In my (un-scientific) testing, I’m seeing about a 50% speed increase in page loads.

possibly very very juicy :slight_smile:

what ProxyPassMatch you have on your virtual host? im stuck there

Without FPM:

With FPM:

Do you get similar readings?

Steps on ubuntu:

1/ installed fpm module with apt (php7.0-fpm)
2/ configured this /etc/php/7.0/fpm/pool.d/www.conf , by adding “listen =” (before was a socket)
3/ included this on the virtual host: ProxyPassMatch ^/(..php(/.)?)$ fcgi://$1
4/ loaded the following php modules: proxy_fcgi
5/ restarted apache and voila

With fastCGI mpm_prefork isn’t ideal. You really want to use mpm_event or mpm_worker, but it’s a little tricker to set up. Also, depending on your server memory, there’s a lot of tuning you can do for php-fpm (www.conf) and apache (mpm_event.conf or mpm_worker.conf)

Here were my steps…

Disabled mpm_prefork, mod_php7.0
Enabled mpm_event, proxy_fcgi
I didn’t use ProxyPassMatch - it causes some issues with .htaccess. I did this instead…

ProxyTimeout 600
<FilesMatch .php$>
SetHandler “proxy:unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/”

Added all the Eramba required php settings to /etc/php/7.0/fpm/php.ini

Just FYI, I’m still having an issue with the daily cron. I really hope I can solve it because fpm makes things so much more responsive.

I had no issues running crons so my guess is something on your end - firewalls most likely if you have timeouts , please schedule a call with !

another update here - it seems that api’s basic auth is not working with fastcgi unless we change a fwe things, we’ll put the fix to give this another shot.

int ref:

@jsalehy i was looking today at fpm server to offload some specific URIs to an alternative server other than the main server. the idea is the browser hits a normal apache+fpm+mysql server but apache has an additional proxy setting that forwards /securityServices URI to another server running fpm

For some reason some things are not as i expect…

On the main server i thought FPM was working (i saw packets on port 9001) but when i looked at the fpm server access logs no matter what section of eramba i use i see only this logs only:

root@dev:/etc/php/7.2/fpm/pool.d# tail -f /var/log/apache2/www.access.fpm.log -  08/Nov/2019:13:45:11 +0000 "GET /app/webroot/index.php" 200 -  08/Nov/2019:13:45:14 +0000 "GET /app/webroot/index.php" 200 -  08/Nov/2019:13:45:13 +0000 "GET /app/webroot/index.php" 200 -  08/Nov/2019:13:45:24 +0000 "GET /app/webroot/index.php" 200 -  08/Nov/2019:13:45:26 +0000 "GET /app/webroot/index.php" 200

My virtual host on apache has only one line (the one above is for the redirection for a specific uri)

I’m not entirely sure what im doing wrong … seems like fpm does not understand the .htaccess on eramba (rewrites, etc) ? … the weird thing is i dont get an error on the browser, i get eramba served by the apache built in php module.

So i thought FPM was working but from the debug above you can see standard php is serving content…i think you mention on your post something about this but i’m not sure what the solution is. maybe you can enlighten?

In regards to the other attempt (redirect a single uri) i get a “File not found” error on the browser, the fpm logs on that server shows:

root@tmpdev:/etc/php/7.2/fpm/pool.d# cat /var/log/apache2/www.access.log -  08/Nov/2019:13:36:09 +0000 "GET /securityServices" 404 -  08/Nov/2019:13:36:34 +0000 "GET /securityServices" 404

Ok - i had an issue on my regex matching php files so now it works , just in case i disabled mod_php on apache and pages load. i still find it weird that the fpm access log shows only index.php no matter what i throw at eramba…no idea why really.

I’ll now keep working on the URI redirect , we want to off load crons to an alternative server. let us know if you tried something like that with success!

Just FYI, I had to add this to my virtual host as well…

SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1

On the fpm logs, you also get only that index.php entry?
i mean mine has to be working, php mod is disabled from apache all-together so there is no other way this would be working …