Installing APC on CentOS 5

By: Colin Foley 10/25/2010

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.

11 Responses to “Installing APC on CentOS 5”

  1. Alexander November 17, 2010

    Finally, at least someone on the interwebs could help me with this stubborn APC install!

  2. Ab December 8, 2010

    have u installed php 5.3.2 on CentOS urself? if so, how?

    Thanx for sharing this information.

  3. just December 13, 2010

    thanx!

  4. James February 2, 2011

    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!!

  5. pat April 18, 2011

    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

  6. Michele May 30, 2011

    thanks, this helped me a lot !

  7. gcb July 22, 2011

    Thanks, same problem same solution.

  8. babak August 5, 2011

    Hey man. thanks for your help.

  9. [...] function and some apc_regex errors. This post outlines how to resolve these issues. The complete solution is at the bottom of the [...]

  10. F@ August 13, 2012

    Thx man ! i’ve been looking for about 2 days…

  11. Ian Lewis March 8, 2013

    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




Developing Mobile Apps for iOS, Android, Windows banner graphic

How can I be sure that I own the intellectual property and source code of my app?

I have a great idea for a mobile application, but I know nothing about designing and developing a mobile app and I want to make...

More questions and answers in The Advice Section

What Our Clients Are Saying

Our confidence in Accella allowed us to introduce them to other divisions in our company, and also one of our most important customers, all of which have now completed multiple development projects.

We considered off-shore developers, briefly, and our company has also considered other providers as new projects arise, but we have always returned to Accella, as we value the consistency in work product, and most of all the ease of working with their staff.

Tim McGough NRP
Zoll Medical

Get a Quote Contact Us