![]() |
Services | Software | Partners | Articles | Contact |
Installing PHP APC on GNU/Linux Centos 5Complex PHP applications, such as Drupal, can gain a lot of performance benefits from running a PHP op-code cache/accelerators.
APC, 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 LinksYou can find some additional tips at Setting up Alternative PHP Caching APC support on Centos server. |




ECHO COMMAND IS WRONG
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.iniIt should be:
echo "extension=apc.so" >> /etc/php.d/apc.iniThat's a rookie mistake. :) Fix your instructions!
Too much noise ...
You are making too much noise without substance.
Double check your facts before making accusations that make you look like a fool in public!
I just checked the above instruction on a pristine CentOS 5.4.
The /etc/php.d/apc.ini file does not exist after pecl installs apc.
# ls -l /etc/php.d
total 4
-rw-r--r-- 1 root root 51 Mar 31 02:51 dbase.ini
Now, we create the file using the instructions I provided:
# echo "extension=apc.so" > /etc/php.d/apc.ini
And now it exists where it has not before:
# ls -l /etc/php.d
total 8
-rw-r--r-- 1 root root 17 Jul 14 10:29 apc.ini
-rw-r--r-- 1 root root 51 Mar 31 02:51 dbase.ini
Learn the difference between /etc/php.ini and /etc/php.d/apc.ini. Perhaps this is lesson will be of some benefit to you.
I still maintain that it'll
I still maintain that it'll overwrite the file if it exists. And yes, I will admit that I got the php.ini and apc.ini files mixed up. Seems to me the better place to include the extension is in the php.ini file, which is where all the other extensions are defined anyway. I believe some of the other install tutorials I found didn't mention the apc.ini file at all and edited the php.ini directly.
So, my error, no big deal. :)
Yes and no ...
Yes, any file that a > is used for will be overwritten. That is standard UNIX shell behavior. No one has debated that.
As for php.ini being a better place, you are wrong again. The whole idea of separating out the configurations into small extension specific files is that they can cleanly be created when an extension is installed and removed when it is uninstalled, without affecting other extensions.
Most distro now do it that way, instead of having one monolithic file that needs to be parsed and edited when an extension is added or removed.
Here is an example from an Ubuntu (Debian derivative) with a few extensions enabled in PHP (they go to /etc/php5/conf.d instead of /etc/php.d, but the same underlying idea).
-rw-r--r-- 1 root root 33 Aug 24 2008 apc.ini
-rw-r--r-- 1 root root 50 Jul 3 2008 gd.ini
-rw-r--r-- 1 root root 75 Sep 26 2009 local.ini
-rw-r--r-- 1 root root 56 Jul 3 2008 mysql.ini
-rw-r--r-- 1 root root 57 Jul 3 2008 mysqli.ini
-rw-r--r-- 1 root root 52 Jul 3 2008 pdo.ini
-rw-r--r-- 1 root root 60 Jul 3 2008 pdo_mysql.ini
-rw-r--r-- 1 root root 804 Aug 8 2009 xdebug.ini
Yeah, no big deal, hence the combative tone of your original comment was unwarranted.
Sorry, I was not able to successfully run APXS
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
It was simple. Very-very simple.
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!
Note these error 1. Perl is
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
php-apc installation
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
Fixed!
On CentOS 5.2 you need to do this to get APXS running:
yum install apr-devel.x86_64
Me too
Same for me - same message. APSX not available, also CentOS 5.2. Installed without.
Pecl may not be able to perform the installation
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.
PECL memory limit change
This 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
Got this working on Ubuntu 7.04 Feisty
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.
Trouble
The installing with your instructions goes just fine, but APC doesnt want to start for me. Apache / PHP gives the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/apc.so' - /usr/lib/php/modules/apc.so: cannot open shared object file: Permission denied in Unknown on line 0
Any help would really be appreciated
Thanks, Khalid. I asked my
Thanks, Khalid.
I asked my host to do it for me and immediately from then onwards, all my drupal pages are showing an internal 500 server error.
Does APC have a problem with php running as suphp (like suexec)?
Thanks,
Venkat
Doesn't work
Actually I recall reading specifically that suexec is known not to work with APC. Perhaps this is because it is CGI (new process every time a request comes in). The only versions that work with APC and other accelerators are the mod_php (Apache) or Fast CGI.
In your case, suexec is a trade off (security vs. performance).
--
2bits -- Drupal consulting
well, it seems to work:-) My
well, it seems to work:-)
My host had simply given incorrect permissions on the temporary APC script. I don't know the intricacies of it, but they said setup would be slightly different on a cPanel VPS and enabled it.
Venkat
suphp
Thanks for the email.
Your site is running suphp (which is still CGI), and suhosin which some say is incompatible with op-code caches (not sure).
Please try with and without APC using devel and see if the pages execute faster with APC on suphp. I doubt they would.
--
2bits -- Drupal consulting
suggestion
Nice and simple tutorial.
One question:
Why APC, and not eAccelerator?
In some of your previous articles (benchmarking APC vs eAccelerator using drupal and PHP op code caches/accelerators: a must for a large site) you wrote that eAccelerator has better performance over APC.
Stability
eAccelerator is definitely better than APC for speed (faster) and memory utilization (uses less memory).
However, with newer versions of PHP and Drupal, APC now has the edge in stability. Previously, we had maybe one or two seg faults with eAccelerator per week, which was acceptable, and the logwatcher script restarted things automatically.
After upgrading, it was seg faulting every 2 hours. Once we switched to APC, it was stable and rock solid.
There is also xcache, which we experimented with, but not used in production work.
I plan to publish updated benchmarks of APC, eAccelerator and xcache in the near future.
--
2bits -- Drupal consulting