Contact Menu

APC Cache Considerations for Virtual Hosting Environments

APC cache does not work well in a virtual hosting environment unless PHP is running as FCGID, and every individual virtual host has a unique PHP.ini and a unique fcgiwrapper. This is not the case with many virtual hosting environments because the memory and CPU requirements are too great.

I suggest using Virtualmin for a shared hosting environment with APC cache, because it does allow to set php.ini and fcgiwrapper for every individual virtual host, and so to set an individual configuration for APC per virtual server. However with 200+ virtual hosts all running PHP script packages, as is the case with a commodity shared hosting server, this will use a lot of memory, and you will need somewhere in the neighborhood of 10-30GB apc.shm_size if you attempt to configure a single APC cache for the entire server.

My web hosting server is for a small number of personal clients, so I adjust the APC settings for each individual account, depending on the number and type of PHP script packages running on the account. These accounts are all administered by myself, not by the clients.

I do not think APC is the correct cache for most shared web hosting servers, given the number of virtual hosts. You will probably have better results if you remove APC and concentrate on Apache performance tuning and MySQL cache.

If your clients are adamant in their requests to use APC cache, you may wish to move them to a different server which can properly handle their needs. Virtualmin is a very good choice for this, as it allows individual accounts to be configured with individual php.ini and fcgiwrapper, or even different versions of PHP. Of course, because this will require greater management, it should be charged as a premium service.

If you wish to enable APC on a commodity web hosting server, you may try the following method to selectively enable APC per directory:
http://www.php.net/manual/en/ini.php

Also see other recommendations in following comments… 

 

, , , , , , , , , , , , , , , , , , ,

4 Responses to APC Cache Considerations for Virtual Hosting Environments

  1. dave March 8, 2012 at 3:02 pm #

    THIS IS ALL REALLY BAD ADVICE… you really shouldn’t be running PHP as FCGID unless you absolutely have to (mod_php is faster). If someone is thinking about using APC to speed up their pages, they definitely should NOT switch to FCGID just so they can use APC. That would just make their server SLOWER. (Whether they use Virtualmin to do that or if you configure it manually, either way it’s the same thing, and it’s a bad idea).

    The “conflicts if scripts are named the same” problem does not exist. (APC caches based on the full file path).

    When running a shared virtual server with mod_php, you can install APC, but configure how it is used for each server using .htaccess and setting APC flags, such as filters. Google “apc htaccess” for info on how to do this properly.

    • Chris Gilligan March 9, 2012 at 12:11 pm #

      Dave, you are correct about the filename conflicts. I’ve removed that paragraph. I did have some issues that appeared to be due to cross-account caching.

      I also agree that FastCGI consumes more memory than mod_php. However, my servers have plenty of RAM and few virtual domains and are optimized for speed instead of number of clients.

      For my needs, servers & clients, and ease of use, APC + mod_fcgid makes sense, and in my experience it is fast and stable. I formerly deployed eAccelerator or Xcache with mod_php, but I prefer fcgid on my current deployed servers. I prefer to tweak apc settings per virtual host, and to run scripts as the virtual server owner/user for ease of administration and allocation of resources.

      I don’t have hundreds or thousands of virtual hosts on my servers, just 10 or so per server, and some sites require different php extensions, so in my case it does make sense to run fcgid and have separate php.ini files for each virtual domain.

      I have not yet used the mod_php and htaccess method, but will try it on a testbed to see if it provides any benefits.

      I would be interested to see objective benchmarks for servers running APC and multiple WordPress installations for mod_php vs mod_fcgid.

  2. Albert May 13, 2014 at 7:29 am #

    I see how this can be used on a small scale with fewer accounts. Do you know of any server benchmarks for mod_php vs mod_fcgid?

Add Comment Register



Leave a Reply