1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP handlers (and opcode caches) for Xenforo on Apache

Discussion in 'Server Configuration and Hosting' started by JoeSchmoe, Jan 2, 2015.

  1. JoeSchmoe

    JoeSchmoe Member

    What sort of PHP handlers people recommend for Apache running on a server with multiple independent sites?

    I'm upgrading from a 1 gig to a 2 gig VPS. I'm putting APC and DSO/mod_php behind me and starting anew. The only limit is that I need to use PHP 5.5 rather than anything newer.

    Right now I'm leaning toward PHP-FPM as the PHP handler. The following graphic, from an excellent slideshow about PHP handlers, explains several of the benefits:


    The core features I need are running as file owner and PHP accelerators (opcode caching).

    I'd like PHP to run as the file owner because I provide hosting services and cPanel logins to 4-5 independent websites and plan to provide more in the future. I don't want people to be able to reach into other people's files. (explanation).

    Regarind opcode caching, I'm leaning toward Zend OpCache because it is built into PHP 5.5, the version I'll be using. I plan to supplement it with Memcached. Everything on our site is PHP and much of it is complex, so PHP acceleration seems like a priority. Alternatively, I could go with xcache since it handles both opcode caching and user caches.

    Any suggestions? Will PHP-fpm, Zend OpCache and Memcached all play well together with PHP5.5? Does this seem like a good stack to go with?

    I'm also considering mod_ruid2. Does anyone have experience with both?

    Many thanks in advance.
    Last edited: Jan 2, 2015
  2. JoeSchmoe

    JoeSchmoe Member

    I should mention that I'm not a pro with all of this and also have a million other responsibilities, so I'll be relying on the tech support from my hosting company (LiquidWeb) to install things. I called them and they said that PHP-fpm shouldn't be a problem to compile, but I don't think it would be wise to try anything much more advanced than that.
  3. Mike Edge

    Mike Edge Formerly Da Bookie Mon

    All our servers use LiteSpeed, not Apache.. But I use FastCGI with Memcache. This is with PHP 5.5 and Percona MySQL5.6 drop-in. We host client communities from just a few posts to 5+ million using this config.
  4. JoeSchmoe

    JoeSchmoe Member

    Thanks, Mike. It sounds like that works very well. 5+ million is pretty huge.

    If I were using php-fpm, I think I would probably use FastCGI to interface with php-fpm. I have a basic idea of how I would configure my httpd.conf for this combination. It would look something like the following code. How would the httpd.conf look different if I were using FastCGI without php-fpm?
    LoadModule fastcgi_module modules/mod_fastcgi.so
      <IfModule mod_fastcgi.c>
        FastCGIExternalServer /usr/sbin/php-fpm -host
        AddHandler php-fastcgi .php
        Action php-fastcgi /usr/sbin/php-fpm.fcgi
        ScriptAlias /usr/sbin/php-fpm.fcgi /usr/sbin/php-fpm
        <Directory /usr/sbin>
          Options ExecCGI FollowSymLinks
          SetHandler fastcgi-script
          Order allow,deny
          Allow from all
    Is there a reference you can point me to or (please!) some code you could paste in?
  5. JoeSchmoe

    JoeSchmoe Member

    For anyone following along, I really appreciated that Mike responded and did some additional research. If you want to get the most you can out of an Apache server (opcode caching, for example) but still have multiple users and care about security, php-fpm should probably be on your radar. (mod_ruid2 also looks good but no one is speaking up for that at the moment and this guy doesn't seem to like it). Also, if you ever want to switch to nginx, for example using centminmod, switching to php-fpm and memcached now may make that easier.

    The following is a great reference on using FastCGI with Apache:

    The following helped me see concretely how php-fpm could be used with Apache:

    The following is a comprehensive overview of FastCGI and Apache. I didn't personally find it as helpful, but it's still one of the better sources and it covers as many options as possible:
    Last edited: Jan 2, 2015
  6. Mike Edge

    Mike Edge Formerly Da Bookie Mon

    Sorry, not sure as I don't use php-fpm. cPanel has it's own FastCGI handler in WHM, recompiling with it using Easy Apache.
  7. Sheratan

    Sheratan Well-Known Member

    Correct me, but you want to use Apache cPanel with php-fpm? or Apache (non-cpanel) with php-fpm?

    I never successfully setup Apache only with php-fpm, if you want to go beyond that (Apache cPanel with php-fpm) I will gladly to hear how to do it.
  8. JoeSchmoe

    JoeSchmoe Member

    Oops, sorry, I meant a reference or some code that would be equivalent to the code I pasted in but would be for FastCGI alone (without php-fpm). Basically, I was hoping you'd paste in some example code from one of your httpd.conf files, suitably anonymized. I didn't know if that was proprietary, though, or if it could be made nonproprietary. I'm happy to take no as an answer. :)
    Our server is a 2 gig WHM/cPanel server, so it would, in that sense, be a cPanel thing. However, as you may know, EasyApache, the cPanel script for updating Apache, doesn't support php-fpm yet. In that sense, it wouldn't be Apache cPanel. Luckily, the awesome tech support at LiquidWeb has said that they expect they could get php-fpm up and running without EasyApache. I'll also learn a lot and do a lot of tweaking of it afterward.
    Last edited: Jan 2, 2015
  9. JoeSchmoe

    JoeSchmoe Member

    By the way, as I've been researching PHP handlers and opcode caches, I periodically find threads from this forum, even when I'm not looking for XenForo specific content. For example, we're the fifth result for the following query:
    Apparently Google things this group is a pretty good place to go for high quality info. Represent XF!
  10. Mike Edge

    Mike Edge Formerly Da Bookie Mon

    I'd strongly suggest not going that route. It can 1) break other cPanel functions. 2) have to be redone everytime cPanel updates a new build. I simply use the FastCGI in Easy Apache with some custom handler tweaks to LiteSpeed config.
    Xon likes this.
  11. JoeSchmoe

    JoeSchmoe Member

    Thanks for the tip. My plan has changed and now is to use FastCGI from within EasyApache.

    Anyone else have thoughts?
  12. shimabuku

    shimabuku Member

    I went with this route. Currently using OPcache and memcache.

Share This Page