The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[StepByStep] Decreasing server CPU load with PHP APC cache extension

Discussion in 'General Discussion' started by FractalizeR, Jan 26, 2008.

  1. FractalizeR

    FractalizeR Member

    Joined:
    Mar 31, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    As you know, each time php script is executed, PHP interpreter need to compile it first to bytecode and only after that - execute. That compilation takes much time.

    APC PHP extension (which will be included and enabled in PHP6 by default. It becomes a standard) can speedup php script execution process by caching once compiled PHP bytecode in memory. So, installing this extension increases your server performance. To install extension just do the following:

    - cd usr/local
    - mkdir apc
    - cd apc
    - wget http://pecl.php.net/get/APC
    After issuing the last command you will have an archive with latest APC source downloaded to your current directory. At the time of writting this article it is APC-3.0.16.tgz. Let's proceed with unpacking it.
    - tar -zxvf APC-3.0.16.tgz
    - cd APC-3.0.16
    - phpize
    - ./configure
    - make
    - make install
    Now locate your php.ini and open it with your default editor. Add anywhere (at the very end for example) the following line:
    Code:
    extension=apc.so
    - service httpd restart

    Now apc extension should be loaded together with your PHP. To test if it is, just take apc.php file from your installation and put it to the directory accessible by your webserver. Open URL in browser and check how your APC is working for you.
     
  2. the_bobara

    the_bobara Well-Known Member
    PartnerNOC

    Joined:
    Sep 23, 2004
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Bulgaria
    cPanel Access Level:
    Root Administrator
    do you know if it is compatible with Zend Optimizer and eAccelerator?
     
  3. FractalizeR

    FractalizeR Member

    Joined:
    Mar 31, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    APC does basically the same as eAccelerator, so there is no reason to install them both.
    As for Zend Optimizer Google says, it is not yet compatible. I didn't investigate a reason.
     
  4. isputra

    isputra Well-Known Member

    Joined:
    May 3, 2003
    Messages:
    576
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Mbelitar
    is it compatible with suhosin and zend ?
     
  5. FractalizeR

    FractalizeR Member

    Joined:
    Mar 31, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
  6. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    There are some issues about installing this that you need to be aware of before jumping in and installing this. In particular, I'm concerned that it is incompatible with suPHP (unless I'm missing something!!).

    Of course your server load depends a lot on your customer mix, however my experience is that the average server is not under pressure from high PHP usage so this actually will not help you very much.

    I would not want to install this on a general access cPanel server. Why? For starters, most general use cPanel servers just aren't under that much pressure from PHP. Note - I'm not saying that it never happens that they're under heavy PHP load, just that it's less common. If you install this, you sacrifice the tremendous security benefits of suPHP for a little performance that doesn't benefit you appreciably.

    The point needs to be made that, without suPHP, everyone on the server can see everyone else's PHP files - and in case you don't understand the significance here, that's really, really bad for security. Sure you can run with safe mode, but there are ways around that. (Suhosin may help, I don't have enough experience with it to comment on it.

    If you do have heavy PHP load, it's normally going to be a few heavy hitting accounts, and of course, they could do well by running with APC PHP compile caching. Usually these accounts are well run (ie software is kept updated, etc) and thus security is not as key, so getting rid of suPHP is not such a huge sacrifice.
     
  7. FractalizeR

    FractalizeR Member

    Joined:
    Mar 31, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    You are probably right. APC is compatible with regular WHM/Cpanel installation. It runs without problems on it. I never tested it on patched PHP configurations.
     

Share This Page