JoomlaWorks

Member Dashboard
  • Home
  • Extensions
    • Commercial
      • Frontpage Slideshow
      • K2 Plugin for sh404SEF
      • Simple Image Gallery Pro
      • SocialConnect
    • Free
      • K2
      • AllVideos
      • DISQUS Comments for Joomla!
      • IAKI (Import As K2 Image)
      • Quick Menu (for Joomla 4)
      • Simple Image Gallery
      • Simple RSS Feed Reader
    • Free On Github
      • Akismet for Kunena
      • Fill It Up
      • K2 Example Plugin
      • K2 Links for JCE
      • Rebuild K2 Image Cache (CLI utility for K2)
      • TinyLetter Subscribe
      • URL Normalizer
      • User Extended Fields for K2
  • Templates
    • Commercial Templates
      • Anagram
      • Archetype
      • BusinessOne
      • Ibento
      • Janaro
      • Kiji
      • Matchbox
      • nuMuzik
      • RadioWave
      • Toreda
    • Free Templates
      • nuModusVersus
      • Takai
  • Demos
    • Joomla Extension Demos
    • Joomla Template Demos
    • WordPress Plugin Demos
  • Labs
    • Web Apps
      • JSON 2 JSONP
      • Feed Reader (bookmarklet)
      • Device Info
  • Support
    • Documentation for Joomla Extensions
      • AllVideos
      • Frontpage Slideshow
      • Simple Image Gallery
      • Simple Image Gallery Pro
      • SocialConnect
    • Documentation for Joomla Templates
      • General Resources
        • Installation
        • Content
        • Customization
      • Commercial Templates
      • Free Templates
    • Get Help
      • Community Forum
        • Recent Topics
        • Categories
        • Create free account
      • Help Desk
      • Contact us by e-mail
      • Contact us on Facebook Messenger
      • Contact us on Twitter
  • About
    • Blog
    • Company
    • License & Terms of Service
    • Privacy Policy
  • My Account
01 12 2010
Written by  JoomlaWorks
Published in Blog
Tagged under
  • +apc
  • +cache
  • +joomla
  • +Performance
  • +session
  • +apcu
  • +mysql
  • +apache
  • +fastcgi
  • +cpanel
  • +whm
23 comments

Install APC/APCu on a WHM/cPanel server the easy way and boost your site's performance!

Install APC/APCu on a WHM/cPanel server the easy way and boost your site's performance!
If you run a popular Joomla (or WordPress, Drupalor or any other PHP based CMS) website on either a dedicated server or VPS running WHM/cPanel, chance is you may have stumbled upon performance issues at some point.

Although improving Joomla's performance is a task that requires in-depth analysis, I thought I'd just write a couple of words on improving one aspect of your site's performance quickly and efficiently: PHP execution by using the APC or APCu opcode caching modules. Keep in mind that APC is compatible with PHP up to version 5.3.x. APCu replaces APC for PHP versions 5.4.x or newer and it's currently under active development.

Since PHP 5.3.x is considered obsolete, I'll cover the steps to have APCu installed on your server. If you run PHP 5.3.x either consider updating to 5.5.x/5.6.x or follow the steps below making sure you replace any "apcu" reference with just "apc" (minus the "u").

There are many tutorials out there covering how to install APCu from command line (as root user), but none on how to install APCu on a WHM/cPanel server " the easy way ". And it's actually pretty easy provided your server is executing PHP in FastCGI mode (the most optimal setup). Default cPanel installations usually run PHP in suPHP mode, which does not allow APCu to be installed. If you have full control of the server, you can use EasyApache in WHM to "rebuild" your system with PHP in FastCGI mode.

FastCGI mode is known to be a fast and secure way to run PHP on your server... FastCGI is also preferred compared to mod_php as it allows websites to execute with the user's permissions (like with suPHP) and as some claim, it's also the fastest from all other PHP builds.

If you want to re-build your server with FastCGI, you can grab a ready-made profile to upload and use in WHM: http://engintron.com/files/cpanel/engintron.dtd

Don't bother trying to install APCu via cPanel's PECL modules installer. It's just broken.

Now, assuming you have PHP in FastCGI mode running on your WHM/cPanel (version 11.48+) based server, here are the steps to install APCu on your server:

1. Install packages

Login via SSH as "root" user on your cPanel server and execute the following commands:

$ yum install make pcre-devel
$ pecl install channel://pecl.php.net/APCu-4.0.10

The first line installs some required packages. Year 2014 or later builds of cPanel should have these installed. If you run the command and the packages are already installed, nothing will happen. The second line will retrieve the latest 4.x build of APCu directly from the PECL code repositories which is compatible with (at the time of writing) the PHP versions (5.x) that ship with cPanel. APCu's v5.x is currently compatible with PHP 7.x only so don't install that until cPanel includes this PHP version too.

Restart Apache via WHM

2. Edit php.ini

Now edit the master php.ini file of the server - usually located in /usr/local/lib/php.ini - to add a couple of configuration options for APCu. Open the file (either with some editor like Coda or via "nano" or "vim") and append these lines at the very bottom of the php.ini file:

[apcu]
apc.enabled = 1
apc.shm_size = 128M

The second line will create a memory pool of 128MBs of cache available from the system to APCu. If you have lots of sites that will use APCu for caching, adjust accordingly.

Restart Apache via WHM.

3. Adjust settings for APCu

If you wish to adjust the APCu values above, you can now do so via "PHP Configuration Editor" in WHM, after selecting the "Advanced Mode" editing option. These 2 values will be at the very top. APCu has a lot more options but "apc.shm_size" is obviously the most critical as it defines the memory pool to hold all cache objects coming from your CMS (Joomla, WordPress etc.).

Remember that whenever your edit your PHP's configuration, you need to restart Apache for the changes to take effect.

4. Keep in mind

If you rebuild your cPanel's LAMP stack with EasyApache, you need to re-install APCu as your changes will be lost. Just follow steps 1-3 once more.

What next?

Wanna go the extra mile and do more to improve your cPanel server's performance, besides the FastCGI setup and APCu? You can obviously optimize your Apache, FastCGI & MySQL configurations:

  • For Apache (make sure you run EasyApache and check Apache 2.4 - it's way better than Apache 2.2), you can have a look at Linode's knowledge base as a starting point https://www.linode.com/docs/websites/apache-tips-and-tricks/tuning-your-apache-server or better still, try using ApacheBuddy to get insights on your existing configuration: https://github.com/gusmaskowitz/apachebuddy.pl

    To give you an idea, this is a good starting point:

    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    ServerLimit 500
    MaxRequestWorkers 500 (this option was previously called MaxClients in Apache v2.2)
    MaxRequestsPerChild 4000
    Timeout 20

    In cPanel, these Apache directives can be configured in "Apache Configuration" (in WHM).
  • For MySQL have a look at this bulletproof configuration we created with the help of Percona (the MySQL experts) a few years ago and updated to today's needs & uses: https://gist.github.com/fevangelou/fb72f36bbe333e059b66 - the file to edit on your server is: /etc/my.cnf
  • For FastCGI/PHP have a look here http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html & here https://www.cloudlinux.com/blog/clnews/perfecting-fastcgi-settings-for-shared-hosting.php - the file to edit on your server is: /usr/local/apache/conf/php.conf

    After you edit this file, you need to "merge" your changes with cPanel so they don't get reset to the defaults when Apache's configuration is updated. If however you rebuild Apache & PHP via EasyApache, you need to run the entire process as the changes to php.conf are reset.

    So after you edit the php.conf file, execute the following commands as root via SSH:

    $ /usr/local/cpanel/bin/apache_conf_distiller --update
    $ /scripts/rebuildhttpdconf
    $ service httpd restart
  • Use Engintron: http://engintron.com/

(updated Jan 2016)
Read 240666 times Last modified on Sunday, 03 January 2016 19:38

23 comments

  • JazZ JazZ 31 Jan 2018
    Comment Link

    Thanks for this ! Easy to follow and works great.

  • Wade Wade 18 Mar 2016
    Comment Link

    Thanks for this excellent tutorial and the update on Jan 16. I had APC working on our server with Magento, but we upgraded php a few weeks ago and APC stopped working.

    Your instructions were perfect for a novice with SSH. We have it back up and running now, thanks to you!

  • Trevor Nelmes Trevor Nelmes 05 Jun 2014
    Comment Link

    Sadly, the apc.so module was not in the list when searched for. Back to square one for me.

  • Fotis Evangelou Fotis Evangelou 23 Mar 2012
    Comment Link


    APC is a PHP extension and I assume it should not conflict in any way with Litespeed. Litespeed is supposed to be fully compatible with whatever Apache is compatible with. If your setup works for you, there's no need to switch to Apache...

  • OpenPotion OpenPotion 23 Mar 2012
    Comment Link


    Ok one more... My server is using Litespeed rather than Apache and APC. And I am setting up clients joomla sites to cache with APC. Do you recommend I scrap litespeed, use apache, and switch to FastCGI? Or can I use Litespeed, APC, and FastCGI? My head is spinning...thoughts my Joomla guru?

  • Fotis Evangelou Fotis Evangelou 22 Mar 2012
    Comment Link


    Symbolic links (symlinks) are just shortcuts. So you can safely delete them.

  • OpenPotion OpenPotion 21 Mar 2012
    Comment Link


    How do you undo that symbolic link if needed?

  • Fotis Evangelou Fotis Evangelou 21 Mar 2012
    Comment Link


    @gswahhab Kinda late to reply (hadn't noticed all comments for some reason via the old Posterous backend) but APC does opcode caching as well, indifferent to Joomla's caching. So it does speedup things a bit. If you install the apc.php file I mention above, you'll have a better overview of what APC does for your site. For the record, getk2.org runs fully on APC without page caching ;)

  • Fotis Evangelou Fotis Evangelou 21 Mar 2012
    Comment Link


    @OpenPotion
    1. APC is natively supported by Joomla unlike XCache and eAccelerator.
    2. To use APC successfully, you need to have cPanel "rebuilt" using FastCGI mode. Adding XCache or eAccelerator makes no difference as they won't be used either way.
    3. Installation is done via the cPanel PECL manager. So is uninstallation. If you don't want PHP to "see" APC, simply navigate to "Service Configuration" >> "PHP Configuration Editor", then "Switch to Advanced Mode" and under section "Core" and ABOVE the command "extension_dir", locate in the input field on the right "apc.so" and simply delete it. This prevents PHP from loading the APC extension.
    4. Symlinks are fine.

  • OpenPotion OpenPotion 21 Mar 2012
    Comment Link


    is your symbolic link command code backwards?

  • OpenPotion OpenPotion 21 Mar 2012
    Comment Link


    and should eAccelerator be disabled?

  • OpenPotion OpenPotion 21 Mar 2012
    Comment Link


    Uninstall directions might be nice in case people want to revert due to issues?

  • OpenPotion OpenPotion 21 Mar 2012
    Comment Link


    What about this thing called xcache I see in EasyApache? Any good? Any things that should be disabled that conflict with APC?

  • Fotis Evangelou Fotis Evangelou 16 Dec 2011
    Comment Link


    @wooo77 Using FastCGI will surely make your server perform better but there is one drawback out of the box: You cannot have custom php.ini files per domain or folder, unless you setup FastCGI to parse them explicitly. An easy solution is to install HTscanner, a PECL plugin like APC, which allows FastCGI servers to have php_flag values inside .htaccess or other custom-name files.

  • woood77 woood77 16 Dec 2011
    Comment Link


    Hello,

    I've been considering this for a while but I don't have much experience with the different php handlers.

    I'm currently running about 200 joomla sites on a single WHM/cPanel server. The average site receives roughly 100 unique visits per day. The server is currently running suPHP as that is what my host recommended for security reasons.

    Would you recommend fastcgi and the apc module based on my configuration and would you consider it as secure as suPHP?

    Thanks guys


  • woood77 woood77 16 Dec 2011
    Comment Link


    Hello,

    I've been considering this myself however I'm not very experienced in the different php handlers.

    I currently have about 200 joomla sites running on a single server. The average site traffic is probably 100 unique hits a day. The server is configured using suPHP for security reasons as that is what my host recommended.

    Would you still recommend fastcgi and the apc module for a configuration like mine and would you say it is as secure as suPHP?

    Thanks guys


  • Fotis Evangelou Fotis Evangelou 16 Dec 2011
    Comment Link


    I've revised my article with some extra info to help you guys out.

  • genesteinberg genesteinberg 25 Nov 2011
    Comment Link


    Nice information, but the installation fails in my installation because the cPanel installer cannot seem to find the apc.so file in the proper directory.

    The default directory is /usr/local/lib/php/extensions/no-debug-non-zts-20090626, and the /usr/lib/ etc., equivalent doesn't help.

    I've asked cPanel to figure it out, since they provide the installer capability. But do you have an alternatives to suggest if it doesn't work.

    Peace,
    Gene Steinberg


  • weltlighting weltlighting 24 Nov 2011
    Comment Link


    the problem is that if i modify the path from /usr/local/lib/php/extensions/no-debug-non-zts-20060613" to "/usr/lib/php/extensions/no-debug-non-zts-20060613 my website is not working, but apc.php is showing me the graphs, if i change it back to /usr/local/lib/php/extensions/no-debug-non-zts-20060613 the website is working fine but apc doesn't....any idea??

  • weltlighting weltlighting 24 Nov 2011
    Comment Link


    hi, amazing tutorial 3 easy steps.

    I have the apc.php file on my server but when i access it it says

    No cache info available. APC does not appear to be running.

    any idea?


  • Start
  • Prev
  • 1
  • 2
  • Next
  • End

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

back to top
BY MAIL BY RSS

Archives

  • March 2023 (1)
  • January 2022 (1)
  • July 2021 (2)
  • May 2021 (1)
  • February 2021 (1)
  • December 2020 (1)
  • September 2020 (1)
  • June 2020 (1)
  • May 2020 (1)
  • February 2020 (1)
  • January 2020 (5)
  • December 2019 (2)

Tag Cloud

allvideos announcement apache community development frontpage slideshow joomla k2 Performance plugin release sh404sef simple image gallery simple image gallery pro simple rss feed reader socialconnect ssh tips update video

Latest Entries

  • New free extension release: Quick Menu (for Joomla 4)
    Written by  JoomlaWorks
    06 Mar 2023
  • Simple Image Gallery (free) v4.2 released
    Written by  JoomlaWorks
    07 Jan 2022
  • Simple Image Gallery Pro v3.9.1 released (bug-fix release)
    Written by  JoomlaWorks
    26 Jul 2021
  • Simple Image Gallery Pro v3.9.0 released
    Written by  JoomlaWorks
    05 Jul 2021
  • Simple RSS Feed Reader v3.9.0 released
    Written by  JoomlaWorks
    25 May 2021

Join Our Newsletter

Enter your e-mail address to subscribe to our new or updated product notifications. We send combined newsletters, so we won't spam you every week :)

Get Social

  • Twitter
  • GitHub
  • Facebook
  • GitHub (K2)
  • YouTube
  • Speaker Deck

Grab Our Feeds

  • Extension Updates
  • Blog
  • Videos
  • Presentations
Copyright © 2006 - 2023 JoomlaWorks Ltd.
JoomlaWorks Ltd. and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.
designed by Nuevvo