Linux, Tips and Tricks, Web DevelopmentSimple 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/'
 Installing '/usr/include/php5/ext/apc/apc_serializer.h'
 install ok: channel://
 configuration option "php_ini" is not set to php.ini location
 You should add "" to php.ini

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

 sudo echo "" > /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)


Categories: Linux, Tips and Tricks, Web Development


  1. May 10, 2014 4:46 am

    Best for knowledge.
  2. phoenixcaramu

    March 26, 2014 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
    1. March 26, 2014 2:02 pm

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

    February 12, 2014 2:47 pm

    Thanks alot! Helped me :)

Post a comment

Your email address will not be published. Required fields are marked *