GIDNetwork > Alternative PHP Cache (APC)
Register
« bad interpreter: No such file or directory Install APC on Windows XP »

Alternative PHP Cache (APC)

by: admin - May 05, 2006

Since 2003, I have been using a PHP optimiser in one form or another. My favourite back then was Turck MMCache for PHP and it was excellent. Unfortunately, the project was abandoned sometime in 2004 because the lead developer was hired by Zend Technologies, if I am not mistaken. For much of 2005, I didn't use any PHP optimizer at all... until recently, when I decided to try installing APC instead.

Alternative PHP Cache (APC) is a free and open opcode cache for PHP.

Below are my notes about installing APC on my Linux Web Hosting Server. My server is powered by CentOS 4.+ and I am using Apache 1.3+ with PHP 4.4+.

More information about APC

You can, of course, read more about APC at PHP.net and also by visiting the PECL web site.

Install APC on Linux (CentOS)

Download APC (replace 'APC-n.n.nn.tgz' below with the correct version number for the latest release e.g. 'APC-3.0.10.tgz'):

Generic Code Example:

[root@server src]$ wget http://pecl.php.net/get/APC-n.n.nn.tgz

Next, you have to extract the files:

Generic Code Example:

[root@server src]$ gunzip -c APC-n.n.nn.tgz | tar xf -

Change directory:

Generic Code Example:

[root@server src]$ cd APC-n.n.nn

Read the INSTALL file:

Generic Code Example:

[root@server APC-n.n.nn]$ cat ./INSTALL | less

Despite this tutorial, you should always read the INSTALL file. It contains all the (latest) information for you to install APC to your web server. I used the "QUICK INSTALL (DSO)" method for installing APC on my web server.

Before you even proceed further, what I can suggest you may want to do next is to find the location of the following files / programmes inside your Linux web server (using the most convenient command: locate, find or whereis):

  • httpd.h e.g. /usr/include/apache/httpd.h

  • phpize e.g. /usr/local/bin/phpize

  • php-config e.g. /usr/local/bin/php-config

  • apxs e.g. /usr/sbin/apxs

You will be using the paths in the (example) command lines described below.

Once you have all the folder information (above) ready, you can start the process of installing APC on your Linux (CentOS) web server.

Generic Code Example:

[root@server APC-n.n.nn]$ /usr/local/bin/phpize

[root@server APC-n.n.nn]$ export CPPFLAGS="-I/usr/include/apache -DAPC_PHP4_STAT"

[root@server APC-n.n.nn]$ ./configure --enable-apc --enable-apc-mmap --with-apxs=/usr/sbin/apxs --with-php-config=/usr/local/bin/php-config

[root@server APC-n.n.nn]$ make

[root@server APC-n.n.nn]$ make install

Tip:
Remember to note down where it copies the apc.so file e.g.:
/usr/local/lib/php/extensions/no-debug-non-zts-20020429/apc.so

Edit php.ini

Open your php.ini file. On my server, php.ini is located at /usr/local/lib/php.ini. Change the default extension directory if you've never set it before:

Generic Code Example:

; Directory in which the loadable extensions (modules) reside.
; extension_dir = "./"
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20020429/"

Notice how I commented out the second line and inserted a new value for the extension_dir setting.

Scroll down the file and insert the following 2 lines to your php.ini file:

Generic Code Example:

extension = "apc.so"
apc.shm_size = 32

;Windows Extensions
;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
;

Again, lines no. 1 & 2 are what I inserted to the file.

Once this is complete, save and close the file.

Restart Web Server

Next, simply restart your Apache web server.

Generic Code Example:

[root@server APC-n.n.nn]$ /sbin/service httpd restart

Verifying / Monitoring APC

If everything was done correctly, you should see a section for APC inside your phpinfo page. Also, you should copy the apc.php page to a suitable location on your web site. For example www.example.com/reports/apc.php:

Generic Code Example:

[root@server APC-n.n.nn]$ cp ./apc.php /home/jds/domains/example.com/public_html/reports/apc.php
[root@server APC-n.n.nn]$ chown jds:jds /home/jds/domains/example.com/public_html/reports/apc.php

Warning:
Please do not forget to edit / reset the password inside apc.php.

Would you like to comment? This story has been viewed 23,570 times.
« bad interpreter: No such file or directory Install APC on Windows XP »

__top__

Copyright © GIDNetwork™ 2001 - 2024

Another website by J de Silva

Page generated in : 0.00697 sec.