Home > Linux, Tips and Tricks, Web Development > Simple PHP-APC setup on Ubuntu 12.04

Simple PHP-APC setup on Ubuntu 12.04

I assume that you already have PHP up and running

Install APC

Method 1: One Step Install ( but you will not get the latest APC )

 sudo apt-get install php-apc
 sudo service apache2 restart

Method 2: Latest Version Install

 sudo apt-get install php-pear php5-dev libpcre3-dev
 sudo pecl install apc

It will ask for some options – just use the default ones ( press enter )
After installation at the end it will display messages like
Build process completed successfully

 Installing '/usr/lib/php5/20100525+lfs/apc.so'
 Installing '/usr/include/php5/ext/apc/apc_serializer.h'
 install ok: channel://pecl.php.net/APC-3.1.13
 configuration option "php_ini" is not set to php.ini location
 You should add "extension=apc.so" to php.ini

make a new file in /etc/php5/conf.d/apc.ini and put a single line in this file

 sudo echo "extension=apc.so" > /etc/php5/conf.d/apc.ini
 sudo service apache2 restart

check for apc in phpinfo() – you should be able to see all the apc variables in the output

php -i | grep "apc"


APC Web Administration

Make a directory in the web root and copy the apc.php file to it

 sudo mkdir /var/www/apc
 sudo cp /usr/share/php/apc.php /var/www/apc/

go to http://localhost/apc/apc.php ( this is insecure )


Securing APC Web portal using .htaccess

create the .htpasswd file outside your web root ( preferably in your home directory )
generate the username and password and copy it to the .htpasswd file

 sudo htpasswd -n apc_admin >> ~/.htpasswd

.htaccess rules for the apc directory – change the AuthUserFile and require user name accordingly

echo "AuthUserFile /home/naveen/.htpasswd" >> /var/www/apc/.htaccess
 echo "AuthName \"Please Log In\"" >> /var/www/apc/.htaccess
 echo "AuthType Basic" >> /var/www/apc/.htaccess
 echo "require user apc_admin" >> /var/www/apc/.htaccess

Add the following lines to the apache config file to allow .htaccess override for the apc directory

 <Directory /var/www/apc>
 AllowOverride All

Make sure that your apache conf file has the below line – else add it

 AccessFileName .htaccess

Restart Apache one final time

sudo service apache2 restart

now go to http://localhost/apc/apc.php and it should ask you for a password


APC Internal Authentication

The apc.php file has credentials to access user cache entries ( disable it – make sure that the below line has the value zero – it might already be set to zero)

  1. Bhushan
    February 12, 2014 at 2:47 PM

    Thanks alot! Helped me🙂

  2. phoenixcaramu
    March 26, 2014 at 6:29 AM

    I can see the apc variables from phpinfo command (php -i); however ../apc/apc.php on the web returns “No cache info available. APC does not appear to be running.” and phpinfo on XAMPP does not show any entries for apc. I noticed username and password entry in the apc.php. Should it be set to my ubuntu root credentials? Any guidance would be appreciated

    • March 26, 2014 at 2:02 PM

      make sure that you have put the apc.so extension in the correct php.ini file for your XAMPP

  3. May 10, 2014 at 4:46 AM

    Best for knowledge.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: