Follow this Blog!

Aug 28, 2013

f Comment

Install APC PHP Opcode Cache on Ubuntu + Nginx in SECONDS!

Amazon Recently I successfully installed APC opcode cache on my Unix machine hosted by Amazon EC2 and I'd like to walk you through the process step by step in case you are doing the same thing.

Below is some version information on my system.

APC Version: 3.1.13
PHP Version: 5.3.2-1ubuntu4.20
NGINX Version: nginx/1.4.1
Ubuntu Version: Ubuntu 10.04.4 LTS

Without further ado let's go!

Install necessary tools
Simply follow the following commands to install necessary tools.

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

If you see an error during executing any of them let me know.

Modify configurations for APC to work
Let's edit our PHP configuration file to enable APC. My PHP configuration file is located at /etc/php5/cgi/php.ini.

$ sudo vi /etc/php5/cgi/php.ini
Add the following line in the very end of the configuration file.
If you just leave it the way it is APC will be using the default values for its configurations, which should do for any average user. You can overwrite any configuration key-value pairs here if you so wish. To see the full list of the configuration keys and accepted values go to

Otherwise let's proceed!

Restart PHP fast CGI and Nginx
$ sudo /etc/init.d/nginx restart
$ sudo /etc/init.d/php-fastcgi restart # this line would boot up APC opcode cache

Now your APC module should be running inside the PHP fast CGI's process.

The following section is not necessary but is recommended so you can verify that APC is indeed working.

View APC stats
Let's assume your server's domain is http://your.server/ and your HTTP server's document root directory is set to /your/doc/root/directory/.

Run the following command.

cp /usr/share/php/apc.php /your/doc/root/directory/
Navigate to http://your.server/apc.php and you should see the following screenshot.

APC PHP Opcode Cache Installed on Ubuntu Nginx

If something is wrong you'll see the following text in the browser.

No cache info available. APC does not appear to be running.
In this case let me know.

If you no longer use apc.php you should delete the file or modify its access permission bits so you don't let the public see your APC stats.

Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael