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.