Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators.

APC,
Alternate PHP Cache, is now the most maintained free/open source op-code cache, and is being used more and more as it emerges to be the
most stable.

The instructions here detail how to get APC running on a CentOS 5 server. The server happened to have Plesk on it as well, which initially made me hesitant to install APC "normally", since Plesk is so picky on what other software is installed on the server. However, it seems to have worked out well.

First, we need the pecl command so we can download and install APC from the repositories.

Do to so, we execute the following command:

yum install php-pear

But, this will not run on its own, we need the following package for the phpize command:

yum install php-devel

We also need the apxs command, which is installed via the following package:

yum install httpd-devel

Now we have all the software we need, so we install apc via the pecl command:

pecl install apc 

Once that finishes, we need to enable apc in Apache's configuration. the following command should do this for us.

echo "extension=apc.so" > /etc/php.d/apc.ini

Then we restart Apache:

/etc/init.d/httpd start

And we are all done. Watch for less execution time per page, and decreased memory usage per Apache process compared to what you had
before.

Links

You can find some additional tips at Setting up Alternative PHP Caching APC support on Centos server.

Comments

Sat, 2008/06/14 - 03:53

I already had PEAR/PECL installed on a system with Apache2 and PHP5, running under Ubuntu 7.04 Feisty.

$ sudo su
# apt-get update
# apt-get install php5-dev
# apt-get install apache2-prefork-dev
# apt-get install apache-dev
# pecl install apc

answer yes when prompted

# echo "extension=apc.so" >> /etc/php5/apache2/php.ini
# /etc/init.d/apache2 stop
# apt-get remove apache2
# apt-get install apache2
# /etc/init.d/apache2 stop
# /etc/init.d/apache2 start
# exit
$

At least I hope this is working. I wish I knew how to test if the performance actually increased.

Due to pecl following an 8 MB restriction that disregards php.ini, pecl may bomb out with a fatal error if you attempt to install apc with it. You can solve this by using the command 'pear install pecl/acp' instead.

I try to install APC following your instruccion but when copile the module I have this error

[root@host ~]# pecl install apc
downloading APC-3.0.19.tgz ...
Starting to download APC-3.0.19.tgz (115,735 bytes)
....................done: 115,735 bytes
47 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
1. Use apxs to set compile flags (if using APC with Apache)? : yes

1-1, 'all', 'abort', or Enter to continue:
building in /var/tmp/pear-build-root/APC-3.0.19
running: /var/tmp/APC/configure --with-apxs
checking for egrep... grep -E
checking for a sed that does not truncate output... //bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for icc... no
checking whether gcc and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-redhat-linux-gnu
checking host system type... x86_64-redhat-linux-gnu
checking target system type... x86_64-redhat-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether apc needs to get compiler flags from apxs...

Sorry, I was not able to successfully run APXS. Possible reasons:

1. Perl is not installed;
2. Apache was not compiled with DSO support (--enable-module=so);
3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs
The output of /usr/sbin/apxs follows
cannot open /httpd/build/config_vars.mk: No such file or directory at /usr/sbin/apxs line 201.
configure: error: Aborting
ERROR: `/var/tmp/APC/configure --with-apxs' failed

My server run on
Centos5
PHP Version 5.2.9

Note that I have no error when execute this previous command:
yum install php-pear
yum install php-devel
yum install httpd-devel

I hope your help.

Regards

Adrian

Tue, 2010/02/16 - 11:01

How to install the PHP APC Extension:

There are two ways to install this extension:

A. Install from Source:

wget http://pecl.php.net/get/APC-3.0.14.tgz
gzip -d APC-3.0.14.tgz
tar -xf APC-3.0.14.tar
cd APC-3.0.14
locate php-config
it is in /usr/bin/php-cong
Create configuration files
Phpize
Compile APC
./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/bin/php-cong
make
make install
Edit pico /etc/php.ini and add this
extension=”” apc.so”
Restart the apache

B. Installing from Yum
yum install php-apc
Go to this path /usr/share/doc/php-pecl-apc-3.0.14/apc.php and copy apc.php into your Document root for access from web
For changing the settings got to this patch
/etc/php.d/acp.ini
Setting parameter
; Enable apc extension module
extension = apc.so
; Options for the apc module
apc.enabled=1
apc.shm_segments=1
apc.optimization=0
apc.shm_size=32
apc.ttl=0
#apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/XXXXXX
apc.enable_cli=1
apc.cache_by_default=1

Tue, 2010/02/16 - 11:06

Note these error

1. Perl is not installed;
2. Apache was not compiled with DSO support (--enable-module=so);
3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs
The output of /usr/sbin/apxs follows
cannot open /httpd/build/config_vars.mk: No such file or directory at /usr/sbin/apxs line 201.
configure: error: Aborting
ERROR: `/var/tmp/APC/configure --with-apxs' failed

install php perl
yum install php-perl
and also install apxs

Tue, 2010/05/11 - 17:28

Had same error:
Sorry, I was not able to successfully run APXS. Possible reasons:

1. Perl is not installed;
2. Apache was not compiled with DSO support (--enable-module=so);
3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs
The output of /var/tmp/pear-build-slezhuk/APC-3.0.19/n follows
/var/tmp/APC/configure: line 3457: /var/tmp/pear-build-slezhuk/APC-3.0.19/n: No such file or directory
configure: error: Aborting
ERROR: `/var/tmp/APC/configure --with-apxs=n' failed

The answer was(for me)... to answer on question "Use apxs to set compile flags (if using APC with Apache)? [yes]" not "y", but "yes". Yes, it matters. Killed 1,5 hours on this. Yes, i also added /usr/sbin to $PATH (it wasn't there for me). Hope it helps somebody!

Wed, 2010/07/14 - 09:43

Jeez, over two years of people overwriting their php.ini files and no one has complained? Perhaps they didn't realize what happened. Or maybe they did and were too embarrassed to respond to you. Didn't test this, did ya? :)

This is 100% dead wrong:

echo "extension=apc.so" > /etc/php.d/apc.ini

It should be:

echo "extension=apc.so" >> /etc/php.d/apc.ini

That's a rookie mistake. :) Fix your instructions!

Pages

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting