How to install PHP APC in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

kahwee:~ kahwee$ sudo pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

kahwee:~ kahwee$ sudo pecl install apc
....done: 148,835 bytes
49 source files, building
...

If you get an error like the following:

...
In file included from /var/tmp/APC/apc.c:44:
/usr/include/php/ext/pcre/php_pcre.h:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/usr/include/php/ext/pcre/php_pcre.h:46: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/usr/include/php/ext/pcre/php_pcre.h:52: error: expected specifier-qualifier-list before 'pcre'
/var/tmp/APC/apc.c:393: error: expected specifier-qualifier-list before 'pcre'
/var/tmp/APC/apc.c: In function 'apc_regex_compile_array':
/var/tmp/APC/apc.c:454: error: 'apc_regex' has no member named 'preg'
/var/tmp/APC/apc.c:454: error: 'apc_regex' has no member named 'preg'
/var/tmp/APC/apc.c:455: error: 'apc_regex' has no member named 'nreg'
/var/tmp/APC/apc.c:455: error: 'apc_regex' has no member named 'nreg'
/var/tmp/APC/apc.c: In function 'apc_regex_match_array':
/var/tmp/APC/apc.c:487: error: 'apc_regex' has no member named 'preg'
/var/tmp/APC/apc.c:487: error: 'apc_regex' has no member named 'preg'
/var/tmp/APC/apc.c:488: error: 'apc_regex' has no member named 'nreg'
/var/tmp/APC/apc.c:488: error: 'apc_regex' has no member named 'nreg'
...

…it is because you do not have PCRE library headers. We can install that with yum:

sudo yum install pcre-devel

After installing that, you should be able to successfully complete the PHP APC installation:

kahwee:~ kahwee$ sudo pecl install apc
...
Build process completed successfully
You should add "extension=apc.so" to php.ini

Finally, you can add “extension=apc.so” to your PHP’s configuration.

nano /etc/php.d/apc.ini

I also added the following settings in /etc/php.d/apc.ini:

extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=32M
apc.cache_by_default=1
apc.stat=1
apc.rfc1867=1 //For Drupal upload progress.
apc.stat=7200 //2 hours

And finally to restart Apache:

/etc/init.d/httpd restart

So to summarize, here’s what I did:

sudo yum install php-devel
sudo yum install httpd-devel
sudo yum install pcre-devel
sudo pecl install apc

Remember to

/etc/init.d/httpd restart

This should work for Red Hat Linux too.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>