Hey there! Today we wanted to give you a brief overview on how setup APC on our Media Temple dedicated virtual server, since sometimes, it’s just a pain in our A%#.
APC optimizes PHP intermediate code and caches data and compiled code from the PHP bytcode compiler in shared memory[1]. Using APC our PHP web applications run faster and it also give us the ability to cache our own data (like query results, html buckets, etc.).
Note that this tutorial is entirely based on a (dv) Dedicated Virtual server from Media Temple with SSH access enabled (if you already have SSH access enabled for your server, please makre sure to also read this tutorial).
The very first thing we need to do is connect to our server using SSH.
Once we logged in, we issue the following command to go to our src folder:
[root@mydvserver ~]# cd /usr/local/src/
Next, we download the latest stable version of APC (as of Jan 30, 2010):
[root@mydvserver src]# wget http://pecl.php.net/get/APC-3.0.10.tgz
--09:57:33-- http://pecl.php.net/get/APC-3.0.10.tgz Resolving pecl.php.net... 76.75.200.106 Connecting to pecl.php.net|76.75.200.106|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 85818 (84K) [application/octet-stream] Saving to: `APC-3.0.10.tgz' 100%[=======================>] 85,818 246K/s in 0.3s 09:57:34 (246 KB/s) - `APC-3.0.10.tgz' saved [85818/85818]
The output tell us that the file was download succesfully, now we need to unpack the file and get his contents, to do so, we issue the following command:
[root@mydvserver src]# gunzip -c APC-3.0.10.tgz | tar xf -
next, we switch to the newly created APC folder
[root@mydvserver src]# cd APC-3.0.10
and then, we prepare the build environment for the APC installation:
[root@mydvserver APC-3.0.10]# /usr/bin/phpize
now our APC is ready to be configured so we issue the following command and wait, it might make take a few seconds (the \ means the line was broke here only for the space, you should write the entire command in one single line):
[root@mydvserver APC-3.0.10]# ./configure -enable-apc -enable-apc-mmap \ -with-apxs2=/usr/sbin/apxs -with-php-config=/usr/bin/php-config
next, we install APC:
[root@mydvserver APC-3.0.10]# make [root@mydvserver APC-3.0.10]# make install
Now APC is installed on our server and ready to be used, the next step we need to take is to tell PHP to start using this module, to do so, we create a new file for this module in the modules folder:
[root@mydvserver APC-3.0.10]# cd /etc/php.d/ [root@mydvserver APC-3.0.10]# vi apc.ini
and inside this file we enter the following (make sure to hit i first to go in insert mode):
extension=apc.so
to save the change, press the Esc key and type
:wq
now, we just need to ask Apache to reload the configuration (so we don’t have to actually restart the web server), to do so, we issue the following command:
[root@mydvserver APC-3.0.10]# apachectl graceful
Now APC is installed and running on our (dv) server.
If you want to see some nice stats, you can copy de apc.php file in /usr/local/src/APC-3.0.19/ to a public folder and then access the apc.php file and you will see a nice stats page like this one:
So that’s it! Pretty quick right?
[1] http://en.wikipedia.org/wiki/Alternative_PHP_Cache#Alternative_PHP_Cache

July 26th, 2010 at 2:42 am
thanks for the breakdown, havin’ a few issues… if i’m uploading the APC file manually via root, do i upload the outer folder, containing a similar named folder + xml file?
basically i’m having issues reaching this step
[root@mydvserver src]# ./configure -enable-apc -enable-apc-mmap \
-with-apxs2=/usr/sbin/apxs -with-php-config=/usr/bin/php-config
terminal says the ./configure file or directory can’t be found?
also i’m noticing a small discrepancy of my login, where you have
[root@mydvserver src]#
i have
[root@mydvserver APC-3.0.14]#
i’d really appreciate some help! feels only steps away.. thanks in adv.!
July 29th, 2010 at 10:41 pm
Hi Adrien!
You actually found a typo in this tutorial but still, it seems that you’re not using the same version we used to write this tutorial, is there any chance you can follow this tutorial using APC version 3.0.10?
Please let us know if that works.
Ever Daniel
Leave a Reply
We would love to hear your feedback. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!