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.
13 Responses
Finally, at least someone on the interwebs could help me with this stubborn APC install!
have u installed php 5.3.2 on CentOS urself? if so, how?
Thanx for sharing this information.
thanx!
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!!
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
thanks, this helped me a lot !
Thanks, same problem same solution.
Hey man. thanks for your help.
Thx man ! i’ve been looking for about 2 days…
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)
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
thanks more, it is working.