Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to install APC on a gentoo with php 5.2 Here teh full command i Lanched:

mkdir /home/APC-php
cd /home/APC-php
tar -xzvf APC
cd APC-3.1.9
./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php5/bin/php-config
make test (i think almost everything failed here)
make install
/etc/init.d/httpd restart

The make install command showed

Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/
Installing header files:          /usr/local/php5/include/php/

When I did after make, make test the output was:

APC: apc_store/fetch with strings [tests/apc_001.phpt]
APC: apc_store/fetch with objects [tests/apc_002.phpt]
APC: apc_store/fetch with objects (php pre-5.3) [tests/apc_003.phpt]
APC: apc_store/fetch with bools [tests/apc_004.phpt]
APC: apc_store/fetch with arrays of objects [tests/apc_005.phpt]
APC: apc_store/fetch reference test [tests/apc_006.phpt]
APC: apc_inc/apc_dec test [tests/apc_007.phpt]
APC: apc_cas test [tests/apc_008.phpt]
APC: apc_delete_file test [tests/apc_009.phpt]
APC: apc_store/fetch/add with array of key/value pairs. [tests/apc_010.phpt]
APC: bindump user cache [tests/apc_bin_001.phpt]
APC: bindump file cache part 1 [tests/apc_bin_002.phpt]
APC: APCIterator general [tests/iterator_001.phpt]
APC: APCIterator regex [tests/iterator_002.phpt]
APC: APCIterator chunk size [tests/iterator_003.phpt]
APC: APCIterator regex & chunk size & list [tests/iterator_004.phpt]
APC: APCIterator delete [tests/iterator_005.phpt]
APC: APCIterator formats [tests/iterator_006.phpt]
APC: APCIterator Overwriting the ctor [tests/iterator_007.phpt]

I already added in /usr/local/lib64/php5/php.ini The extension_dir is extension_dir = "./"

To make apc loaded I had to put the file in my www directory. Now phpinfo(); says it's loaded.

The problem is that apc_store doens't effectively store the data between requests.

$bar = 'BAR';
apc_store('foo', $bar);

Within one request this work.

Now If i try to do a var_dump(apc_fetch('foo')); on another request it prints:


It is like APC isn't running in background but it starts only for each requests

Isn't this bounty worth the question? :(

share|improve this question
What does locate phpize show (you may have to emerge slocate and run updatedb first)? Is PHP 5.2 installed through portage or manually compiled? I see you're specifying /usr/local/bin/php-config as your php-config, did you try /usr/local/bin/phpize? – Eduardo Ivanec May 27 '11 at 0:31
Thanks! I found that all bins where in /usr/local/php5/bin I did all that commands and restarted apache but still the apc_* func where not available :( – dynamic May 27 '11 at 10:00
Ugh. Gentoo. Good luck with that. – Tom O'Connor Jun 3 '11 at 16:45
up vote 0 down vote accepted

From the information you've provided, it looks like you've compiled most of your required packages from scratch rather than using the Gentoo package management system known as Portage. Taking the install-from-source route is generally a bad idea unless you know exactly what you're doing. While it is true that the default behaviour of Portage is also to install packages from source, it has an advanced dependency management toolset which handles most complex dependencies automatically, and makes updating and removing packages quite painless.

The following files and directory locations which you specified are all non-standard in a typical Gentoo configuration, and will most certainly cause interdependent packages to fail or crash unexpectedly:


If this is not a production box, and you can spare the downtime, I suggest completely removing Apache and PHP, and then reinstall them using Portage as follows:

Install Apache:

emerge -av www-servers/apache

Next, you'll need to install PHP, but be sure to set the apache2 USE flag. Adding your USE flags to /etc/portage/packages.use ensures that they will be retained across future updates. A typical set of USE flags set for PHP in /etc/portage/packages.use will look like this:

dev-lang/php apache2 berkdb bzip2 calendar cli crypt ctype curl curlwrappers fileinfo filter ftp gd gdbm hash iconv imap inifile ipv6 json ldap mssql mysql mysqli nls pdo phar posix readline session simplexml snmp soap sockets spell sqlite ssl threads tokenizer truetype unicode xml xmlrpc xsl zip zlib

You should be able to remove most of the USE flags I provided in this example, except for the apache2 flag. Your particular requirements will determine the USE flags you need to set, but for a base installation of PHP which will work with Apache, you only require the apache2 flag to be set.

Now that you have the USE flags set, you can go ahead and install PHP:

emerge -av dev-lang/php

Once PHP has installed successfully, you can confirm that it has been correctly configured to work with Apache by opening /etc/conf.d/apache2 in a text editor and checking that the line starting with APACHE2_OPTS contains the directive -D PHP5.

You can now start Apache by invoking the correct init script:

/etc/init.d/apache2 start

There should be no problems starting Apache at this point. The next step requires some changes to PHP, so you should stop Apache again in the meantime.

Gentoo splits the PHP configuration files into two separate directories, one for configuring the PHP CLI, and the other for configuring PHP used with Apache. These directories are as follows:


Your exact path may differ slightly depending on the exact version of PHP you have installed.

The last step is to install APC, again using Portage:

emerge -av dev-php5/pecl-apc

Once APC has been successfully installed, you may need to edit the /etc/php/apache2-php5/php.ini file to check that APC is correctly configured and to ensure that PHP loads the extension when Apache is started. Check that the following are present in the php.ini file:


The full list of APC configuration directives are available here on the PHP online docs.

You have now completed all steps required for correctly configuring Apache, PHP and the APC extension for a Gentoo environment. Restart Apache to finish.

/etc/init.d/apache2 restart
share|improve this answer
without even reading +150 – dynamic Jun 5 '11 at 22:54

I had similar problems in the past.

Try to add this line to your php config


Anyway, why aren't you using pecl-apc package from gentoo?

share|improve this answer
the problem is i ma under CGI interface. I dunno how to change that – dynamic Jun 3 '11 at 15:42
Probably that's the problem, APC doesn't share memory between processes, and CGI create a new process per request. May be the answer is to use something else, like memcached. – erickzetta Jun 3 '11 at 17:45
hm! good tip!.. but is that hard to run php normally under apache? – dynamic Jun 3 '11 at 18:09
Usually, it's very easy. In gentoo, just install apache and php with apache2 useflag. – erickzetta Jun 3 '11 at 20:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.