Installing APC on CentOS 5

There can be several issues when installing APC on a CentOS based operating system with PHP 5.3.2. These include a duplicate ‘static’ error in the zif_apc_compile_file function and some apc_regex errors. This post outlines how to resolve these issues. The complete solution is at the bottom of the post.

I’ve just recently had the opportunity to work with Amazon’s cloud services.  As a newcomer to Amazon’s services, I was a bit skeptical; Amazon is, after all, an online retailer.  After a few hours working on the server and reading up on Amazon Elastic Compute Cloud (Amazon EC2), my mind was changed.  The server is blazing fast and so is its Internet connection.

The machine we’ve got has an operating system based off of CentOS running on it.  If I had my way, I’d only ever use Debian-based operating systems and if I could get away with it I’d just plop versions of Ubuntu on servers and get rolling.  It’s probably a good thing I’m not a server administrator.  Anyway, I ran into some issues installing the Alternative PHP Cache (APC) on this machine. If you don’t want to read all my anecdotes, go to the solution.

The first commands I ran were:

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

The zeroth issue I ran into was that the server didn’t have a c compiler and the APC install couldn’t complete. A simple install of gcc solved this issue:
sudo yum install gcc

So, then I tried sudo pecl install apc again and the first issue I ran into was an error like this:

/var/tmp/APC/php_apc.c: In function 'zif_apc_compile_file':
/var/tmp/APC/php_apc.c:881: warning: unused variable 'eg_class_table'
/var/tmp/APC/php_apc.c:881: warning: unused variable 'eg_function_table'
/var/tmp/APC/php_apc.c: At top level:
/var/tmp/APC/php_apc.c:959: error: duplicate 'static'
make: *** [php_apc.lo] Error 1
ERROR: `make' failed

Because I’m stubborn, I went ahead and added the apc.so extension in my php configuration hoping that the error didn’t mean anything and that APC succesfully installed anyway:
sudo touch /etc/php.d/apc.ini
This code places a file called apc.ini in the directory that php checks for configuration files while it is loading.
I then put this line into /etc/php.d/apc.ini:
extension=apc.so
While APC still didn’t work, I didn’t have to do this step later.

I continued trying to install APC through different ways: from yum, from source, from pear, and from pecl. I finally got further in the installation process using the command: sudo pecl install apc-beta Notice that I said, “Further in the installation process,” not, “all the way through the installation process.”

The second issue I ran into was an error like this:
In file included from /usr/local/src/APC-3.1.2/apc.c:38:
/usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
In file included from /usr/local/src/APC-3.1.2/apc.c:38:
/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'
/usr/local/src/APC-3.1.2/apc.c:362: error: expected specifier-qualifier-list before 'pcre'
/usr/local/src/APC-3.1.2/apc.c: In function 'apc_regex_compile_array':
/usr/local/src/APC-3.1.2/apc.c:419: error: 'apc_regex' has no member named 'preg'
/usr/local/src/APC-3.1.2/apc.c:419: error: 'apc_regex' has no member named 'preg'
/usr/local/src/APC-3.1.2/apc.c:420: error: 'apc_regex' has no member named 'nreg'
/usr/local/src/APC-3.1.2/apc.c:420: error: 'apc_regex' has no member named 'nreg'
/usr/local/src/APC-3.1.2/apc.c: In function 'apc_regex_match_array':
/usr/local/src/APC-3.1.2/apc.c:452: error: 'apc_regex' has no member named 'preg'
/usr/local/src/APC-3.1.2/apc.c:452: error: 'apc_regex' has no member named 'preg'
/usr/local/src/APC-3.1.2/apc.c:453: error: 'apc_regex' has no member named 'nreg'
/usr/local/src/APC-3.1.2/apc.c:453: error: 'apc_regex' has no member named 'nreg'
make: *** [apc.lo] Error 1

What you need in this instance is the pcre-devel package: sudo yum install pcre-devel

Complete Solution

In short, this is what you need to run to get APC installed  (gcc install only required if you don’t have a C compiler):

sudo yum install php-pear
sudo yum install php-devel
sudo yum install httpd-devel
sudo yum install gcc
sudo yum install pcre-devel
sudo pecl install apc-beta

Then add extension=apc.so to your php.ini file or a config file such as apc.ini inside the php.d/ directory.

Many thanks to various and sundry bloggers who helped me on the way including LONGVNIT who really came through in the clutch with the pcre-devel package suggestion.

Colin Foley

Colin Foley

Colin's programming career began in high school where he began to learn the ins and outs of the Java language. While attending Lehigh University, he focused his efforts on web development. Ever since then, the majority of his work experience has been developing websites with PHP, MySQL, Adobe ColdFusion, J2EE, HTML and CSS.

13 Responses

  1. Thanks for this a lot!! I’m sure it will help a LOT of people like it did me. I was stuck after it kept complaining about the preg/nreg, but luckily this saved me with the pcre-devel install.

    Thanks so much for this!!

  2. works like a champ. I fiddled around for 2 hours until i found this post. Worked perfectly, APC is running on my site, performance is significantly improved.

    thx,

    p

  3. please help?
    i heave problem in:

    –> Finished Dependency Resolution
    php-devel-5.1.6-39.el5_8.x86_64 from updates has depsolving problems
    –> Missing Dependency: php = 5.1.6-39.el5_8 is needed by package php-devel-5.1.6-39.el5_8.x86_64 (updates)
    Error: Missing Dependency: php = 5.1.6-39.el5_8 is needed by package php-devel-5.1.6-39.el5_8.x86_64 (updates)

  4. HI,

    Great advice.. even better when I read as far as the solution you finally found.

    Can I suggest removing the console lines from above that lead to the failure.. I suspect that many will do as I did and C&P the non-working lines in.

    Luckily I kept on reading and found the working solution – all credit to you for that!

    Thanks

Leave a Reply

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

Categories

Search

Recent Posts

Tags