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 packagesLogin 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.iniNow 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:
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 APCuIf 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 mindIf 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:
MaxRequestWorkers 500 (this option was previously called MaxClients in Apache v2.2)
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
$ service httpd restart
- Use Engintron: http://engintron.com/
(updated Jan 2016)