How to install APC on Linux
About week ago I made post about using APC caching with PHP. As I noticed – this post was pretty popular, I even got several responses to personal email regarding this post. Today I will tell you how to install APC (for PHP) on Linux system.
Pay attention – for installing you will need to have root SSH access. This operation usually permitted at hostings like VPS/VDS, but not at shared hostings.
Step 1 – Downloading APC
Firstly – you need to download APC package from PHP PECL library. I can advice to download APC package to /opt folder at server or in account (but not to ‘www’ folder). Ok, now lets connect to our host via SSH (Putty as example), goto selected folder for APC package (as example /opt), and run next command:
$ wget http://pecl.php.net/get/APC
This command will download latest version of APC. Novadays – this is APC-3.1.9.tgz. In result – we will see that this file appear in our folder:
$ ls -al total 200 drwxr-xr-x 3 root root 4096 Aug 27 23:35 . drwxr-xr-x 20 root root 4096 Sep 19 12:36 .. -rw-rw-r-- 1 xmusics xmusics 155540 May 14 15:15 APC-3.1.9.tgz
Step 2 – Extracting package
Here are easy command for extracting archive:
$ tar -zxf APC-3.1.9.tgz
In result – new folder ‘APC-3.1.9′ will appear. Lets enter inside
$ cd APC-3.1.9
Step 3 – phpize
Now we need to run ‘phpize’ command:
$ phpize
This command required to prepare a PHP extension for compiling
Step 5 – configure
Now we need to configure our APC (pointing where located our php-config), lets search where we have php-configs:
$ whereis php-config
In result we can see something like this:
$ whereis php-config php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
First one looks correct path, second one related with ‘man’ (this is short from Manual). So, now lets run next command to configure APC:
./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
During execution it will show you many different information, different checking, creating etc.
Step 6 – make
Now we need to run ‘make’ command:
$ make
In result – it can executed successfully:
$ make ....... Build complete.
Or we can get error:
$ make ....... In file included from /opt/APC-3.1.9/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 /opt/APC-3.1.9/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' /opt/APC-3.1.9/apc.c:362: error: expected specifier-qualifier-list before 'pcre' /opt/APC-3.1.9/apc.c: In function 'apc_regex_compile_array': /opt/APC-3.1.9/apc.c:419: error: 'apc_regex' has no member named 'preg' /opt/APC-3.1.9/apc.c:419: error: 'apc_regex' has no member named 'preg' /opt/APC-3.1.9/apc.c:420: error: 'apc_regex' has no member named 'nreg' /opt/APC-3.1.9/apc.c:420: error: 'apc_regex' has no member named 'nreg' /opt/APC-3.1.9/apc.c: In function 'apc_regex_match_array': /opt/APC-3.1.9/apc.c:452: error: 'apc_regex' has no member named 'preg' /opt/APC-3.1.9/apc.c:452: error: 'apc_regex' has no member named 'preg' /opt/APC-3.1.9/apc.c:453: error: 'apc_regex' has no member named 'nreg' /opt/APC-3.1.9/apc.c:453: error: 'apc_regex' has no member named 'nreg' make: *** [apc.lo] Error 1
I very hope that you don`t will get this error and your make will successfull, but if not – don`t worry. Lets understand why it happen, As we can see – first error related with: ‘php_pcre.h:29:18: error: pcre.h: No such file or directory’. What it mean, that compiler not find ‘pcre.h’ file, right? This file located (should) in PHP development package (php-devel). So, to solve our problem – we will need to install that extra package ‘php-devel’ with ‘pcre’. To install it, execute next command:
$ yum install pcre-devel
Then, lets repeat our ‘make’ command:
$ make
This time the command should successfully executed
Step 7 – Installing
Executing next command:
$ make install
Here we don`t should have problems like before
Step 8 – Restarting
Now we need just restart our server (to apply changes):
$ /etc/init.d/httpd restart
Thats all my friend, we just finished installing APC caching system to our hosting. But how to confirm it? Easy – just execure phpinfo() command and search for ‘APC’ section. This can be like this:
Thanks for the Tutorial
I already install APC on Windows and on ubuntu.
But not able to install on a shared hosting where i have only cpanel.
i can install only pear packages easy using “pear packages”.
please help me or guide me.
thanks
Seems like this is a specific setup for PHP run by Apache but I may be wrong. Can you explain what these flags do and why they should be set?
–enable-apc-mmap
–with-apxs
Hi Dash,
As I know – ‘with-apxs’ key mean ‘PHP can be installed as a loadable module of Apache’
so about ‘enable-apc-mmap’ – this is memory mapping support
Hmm, I not sure about possibility to install APC at shared server, just because you even don`t will have rights to recompile PHP
Great tutorial. So simple and easy to follow. many thanks
when i run this command “apt-get install pcre-devel”
i see this massege:
[
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package pcre-devel
]
what can i do now?
pls inform me…
Hello Tazim,
Did you try
apt-get install pcre-devel
or
$ yum install pcre-devel
?
Try to second one (as in our manual)