PHP-FPM (FastCGI Process Manager) + Wordpress

Discussion in 'Linux VPS/Dedicated - cPanel' started by Isaias, Feb 10, 2014.

  1. Isaias

    Isaias New Member

    Someone is using php-fpm with Wordpress? What can you tell me about? This feature is already available in the VPS?

    What did you think about?
  2. KH-Jonathan

    KH-Jonathan Director of Managed Services Staff Member

  3. Anoop Alias

    Anoop Alias New Member

    Last edited by a moderator: Jun 6, 2014
  4. Dion

    Dion Member

    I have now used a variant of the cphstack script to enable php-fpm on my KH VPS, as well as on those of two clients (one on KH and one, um, not). Everything seems stable, and every site is freakishly fast.

    If the results I've seen are any indication, getting php-fpm installed are well is well worth the (minor) hassle. Some quick need Apache 2.4 with MPM/Event, and preferably PHP 5.5 with OPcache. The fpm socket problems in PHP 5.4 were apparently solved in 5.5, and OPcache seems to be optimized for php-fpm as it works much better with php-fpm than it does with the FastCGI or DSO handlers.

    The "ondemand" FPM pool option works incredibly well on sites that get fewer than a couple page hits/second. I'm still tweaking the "dynamic" option on a large site, but even without optimized settings, the site is noticeably faster than it was with DSO/APC, the memory usage is almost identical, and FINALLY, Apache is running PHP as the cPanel user and not as nobody!

    Having said all this, I do not recommend using this script unless you take a good look at it first to determine if it will damage your server. The script blindly creates files and directories without first checking whether they exist. For example, I use a custom vhost.local EasyApache script on my VPS. Had I allowed the cphstack script to run, it would have wiped out my custom virtual host configuration.

    The best course of action would be to download all the necessary files yourself, create/copy the files and directories manually, and then run the necessary programs. Or, hopefully, have the good techs at KnownHost customize the script for their internal use when a customer asks if php-fpm can be installed. ;)
    hostingdoc and WebEndev like this.
  5. WebEndev

    WebEndev Member

    THAT would be seriously awesome!
    Is it a possibility?
  6. Dion

    Dion Member

    I've found a real problem using php-fpm with Apache -- environment variables aren't passed properly. This is causing some Apache modules to not work as they should. For example, mod_deflate will not compress .php files, and variables set with "SetEnvIf" are ignored.

    Apparently this is a bug in the ProxyPassMatch directive in mod_proxy. One hopes it is fixed soon, because the performance of php-fpm is really amazing. In the meantime I am going to disable php-fpm because I really need to use SetEnvIf and would prefer to serve GZipped .php files.
  7. Dion

    Dion Member

    Well, I finally got PHP-FPM working with no bugs...and it's both stable and FAST. I used the following in pre_virtualhost_global.conf:

    <Directory "/home/username/public_html">
    	<FilesMatch \.php$>
    		SetHandler proxy:unix:/var/run/php-fpm/username.sock|fcgi://localhost/
    		Require all granted
    Lo and behold, PHP-FPM worked perfectly. All the problems I described above were gone, and the speed...WOW.

    You MUST use "Require all granted" -- the Apache 2.2 allow/deny rules will not work, even though mod_access_compat is installed. Substitute "username" for the cPanel user of your choice.

    The SetHandler method to enable PHP-FPM requires Apache 2.4.9 (or later) and PHP 5.5.18 (or later). While MPM-Event is not required, it should be used for performance reasons. In addition, Zend OPCache works incredibly well with PHP-FPM and should be used in favor of APC, XCache, or EAccelerator. (If you desire an object cache, use APCu.)

    I hope this is of help to folks here.
    action likes this.
  8. Dion

    Dion Member

    Quick edit...leave off the forward slash after localhost, as follows:

    SetHandler proxy:unix:/var/run/php-fpm/username.sock|fcgi://localhost
    Otherwise Apache will set an incorrect value for SERVER['SCRIPT_FILENAME'].
  9. KH-Jonathan

    KH-Jonathan Director of Managed Services Staff Member

    Great work Dion!!

    I'm a huge fan of PHP-FPM and APC and a lot of our internal stuff uses it but for an upgrade being worked on for one of our systems I've been toying with PHP 5.6 and Zend Opcache and I must say, the numbers are impressive. I see about a 20-30% decrease in page generation time with 5.6+Opcache over 5.4+APC.

    Wish I could find some sort of status page for Opcache like APC has. I've always found that to be a nifty feature of APC.

    Get the most from your host - buy VPS hosting from KnownHost for 24/7 support, instant setup and complimentary DDOS protection.
  10. KH-Jonathan

    KH-Jonathan Director of Managed Services Staff Member

  11. Dion

    Dion Member

    After using for a while now, I am convinced that OPCache was designed for use with PHP-FPM. It's amazing how much better it now seems to work.

    One thing I forgot to mention above. If the PHP configuration is changed, you must restart PHP-FPM in addition to Apache, or the changes will only be reflected in the CLI version of PHP.

    If the contents of the proxypassphp.include file in cphstack were replaced with the following:
    	<Directory "[% vhost.documentroot %]">
    		<FilesMatch \.php$>
    			SetHandler proxy:unix:/var/run/php-fpm/[% vhost.user %].sock|fcgi://localhost
    			Require all granted
    it should be pretty easy to convert the script (and accessory files) to be used on a KH VPS.

    I just installed this on a client's KH VPS-2, and the site went from sluggish to fairly responsive. I thought the client needed a larger VPS. I was wrong. ;)
  12. Pie

    Pie New Member

    Seems like you guys know what you're talking about! Very honored to be in your company. :)

    I'm about to move a WordPress blog (simple text and images, no memberships) to KH. It gets about 10-20k pageviews/day, but the challenge is coping with the simultaneous traffic it gets when I plug links on social media. Usually, that'll bring in a few hundreds of simultaneous visitors (which breaks the site on Siteground, who tried to upsell me a dedicated server as a solution), but I would like the site to be able to handle even 1000-2000 simultaneous visitors, just in case something goes viral. I don't mind the site being a bit slower, you know, just as long as it doesn't go blank on the new traffic.

    I'm on KH's SSD-2 plan (I know I might have to upgrade with that kind of traffic, but just testing the waters) and I've had them install Varnish, nginx and mod_pagespeed. Is that a good combo, or should I go the PHP-FPM and APC route as suggested above?

    I'm not technical at all, so any tips, configurations, etc. are very much appreciated!
  13. KH-DavidL

    KH-DavidL Abuse & Documentation Specialist Staff Member

    We're honored to have you as part of the family!

    Also websites are different and there are plenty of options out there. Currently, I'm running FastCGI with mod_pagespeed and I'm pleased with the results.
  14. WebEndev

    WebEndev Member

    Hi Pie,

    How does that setup work for you? Any issues? Have you run your WordPress site on it yet?

    I had KH install Nginx via the plugin and it works great. Is this what you are using?

    I was thinking of adding mod_pagespeed, but I did not know if it would work with the Nginx plugin?

    How did the install Varnish for you?

    Any input by KH staff is very welcome :p

  15. Pie

    Pie New Member

  16. WebEndev

    WebEndev Member

    I'll be curious to see how your WordPress site runs, and if you have any issues with that set up. Thanks for the info!
  17. Pie

    Pie New Member

    Will do. I'm also going to do some load testing first with, and/or

    Meanwhile, any WordPress cache wizards around? Please apply within :)
  18. Franky

    Franky New Member

    Is PHP-FPM applicable for high traffic sites with lots of images? Moving from VPS to dedicated server now. I'm not really a techie person but can you also install PHP-FPM on dedicated server besides VPS?
  19. KH-Jonathan

    KH-Jonathan Director of Managed Services Staff Member

    PHP-FPM is best for high-traffic sites actually. It's not supported by cPanel but as you can see here people have managed to get it working.

    The stuff internally of ours I referred to running it doesn't run on top of cPanel obviously. I've found Nginx+PHP-FPM+ZendOpcache to be a pretty mean combination, but again, this was all setup manually without cPanel.
  20. Pie

    Pie New Member

    Want! Hey Jonathan, my support guy (#493187) is recommending to go back to DSO PHP but that doesn't feel right. Would you mind taking over and setting up that mean combination of yours, please?

Share This Page