Tuesday, June 8, 2010

install PECL APC Cache on CentOS

SkyHi @ Tuesday, June 08, 2010

As Irakli already discussed, the Alternative PHP Cache (APC) is an op-code pre-compiler and a cache system that can boost the performance of a PHP application up to 10 times. Op-code caches are very effective for a Drupal website, since Drupal deals with large number of source files and time spent in parsing them significantly affects performance. However, if you don’t have XAMPP and need to install it on CentOS, you can follow this to get around some of the problems that happen with the default server settings. h2. Install Pre-reqs Using yum install the required prerequisites.




sudo yum install php-devel php-pear httpd-devel


Install APC



Use the command




sudo pecl install apc


at this point you’ll likely see the error




Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 92160 bytes) in /usr/share/pear/PEAR/PackageFile/v2/Validator.php on line 1831


Apparantly, the PECL/PEAR scripts do not use the settings from /etc/php.ini so you need to update PEAR’s memory settings to give is some more breathing room. Edit the file /usr/share/pear/pearcmd.php and add the following at the beginning:



@ini_set('memory_limit', '16M');


Configure/Restart



Now configure PHP to use the new extension. Create the file /etc/php.d/apc.ini and in that file put:



echo "extension=apc.so" > /etc/php.d/apc.ini


Now restart apache



sudo /etc/init.d/httpd graceful


Maintenance



In the future, if new versions of APC are released, you can easily upgrade them using



sudo pecl upgrade apc


I hope this helps!



REFERENCES

http://www.agileapproach.com/blog-entry/howto-install-pecl-apc-cache-centos-without-xampp

###check comments###

http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html

http://2bits.com/articles/php-op-code-caches-accelerators-a-must-for-a-large-site.html

http://2bits.com/articles/benchmarking-apc-vs-eaccelerator-using-drupal.html

http://2bits.com/articles/benchmarking-apc-vs-eaccelerator-using-drupal.html

http://2bits.com/articles/benchmarking-drupal-with-php-op-code-caches-apc-eaccelerator-and-xcache-compared.html


http://2bits.com/contents/articles


Installing APC for vBulletin on CentOS 5
Server



You can find out if APC is now running by loading a phpinfo() page (vBulletin AdminCP > Maintenance
> phpinfo) and search for APC block.



Now that it works, go into the includes/config.php file
and enable the datastore class to use APC:

Find:

Code:

// $config['Datastore']['class'] = 'vB_Datastore_Filecache';

and replace it with

Code:

$config['Datastore']['class'] = 'vB_Datastore_APC';

Still in the config.php file you will now find (from 3.7.1 and
up) the following option:

Code:

// $config['Datastore']['prefix'] = '';

I recommend to change this if you have multiple forums running
on the same box. Since each of my forums uses a unique table prefix
based on the domain name, I am using this table prefix for the datastore
APC prefix too. Example; my web site vbulletin-fans.com is vbfans_ as
table prefix. So I will use this for this instance:

Code:

$config['Datastore']['prefix'] = 'vbfans_';

Keep this as simple and short as possible, but unique.



To test if it works your PEAR/APC should have come with a file called
apc.php. You can now copy this to your vBulletin's directory and edit
the file. Set a new user/pass for authentication and load the file in
your browser. When you're done you can remove the apc.php file from this
public dir.



And you're done.



I hope this helps some site owners to get a bit more performance out of
their vBulletin powered community and give their visitors a more snappy
experience. Note that 3.7 support APC but it works just as well without
it. Hopefully in the future (say version 4 and up) vBulletin will make
more and better use of op-cache like APC.




REFERENCES
http://www.vbulletin.com/forum/entry.php?2234-Installing-APC-on-CentOS-5-Server
http://mrfloris.com/vbulletin/installing-apc-on-centos-5-server/