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
Visitor (not verified)
Got this working on Ubuntu 7.04 Feisty
Sat, 2008/06/14 - 03:53I already had PEAR/PECL installed on a system with Apache2 and PHP5, running under Ubuntu 7.04 Feisty.
answer yes when prompted
At least I hope this is working. I wish I knew how to test if the performance actually increased.
Visitor (not verified)
Pecl may not be able to perform the installation
Thu, 2008/11/20 - 23:05Due 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.
Visitor (not verified)
PECL memory limit change
Tue, 2009/10/27 - 06:42This didn't work for me, but I found this post by Phase2 which tells you how to increase the memory PECL can use:
http://www.agileapproach.com/blog-entry/howto-install-pecl-apc-cache-centos-without-xampp
Visitor (not verified)
Sorry, I was not able to successfully run APXS
Fri, 2009/09/04 - 17:49I 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
Visitor (not verified)
Me too
Tue, 2009/10/27 - 06:44Same for me - same message. APSX not available, also CentOS 5.2. Installed without.
Visitor (not verified)
Fixed!
Tue, 2009/10/27 - 06:49On CentOS 5.2 you need to do this to get APXS running:
Visitor (not verified)
php-apc installation
Tue, 2010/02/16 - 11:01How 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
Visitor (not verified)
Note these error 1. Perl is
Tue, 2010/02/16 - 11:06Note 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
Visitor (not verified)
It was simple. Very-very simple.
Tue, 2010/05/11 - 17:28Had 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!
Visitor (not verified)
ECHO COMMAND IS WRONG
Wed, 2010/07/14 - 09:43Jeez, 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