web analytics

Enabling OPCache on Ubuntu 14.04 with Apache

Having a blog or website with thousands of visitors would be nice, it means your articles are read by many people, it also means that you can earn a lot of money on advertising, right? 😛

A good website is not just about good design and interesting articles, but also the page load speed. Imagine if you open a web page that takes 2 minutes more, infuriating, isn’t it?

If you are using WordPress or other CMS based on PHP and running on a VPS, you can optimize the performance with OPCache. OPCache is an extension bundled with PHP 5.5.0 and later.

OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

Follow a few steps below to enable OPCache on your Ubuntu server:

1. Remote your server via SSH

2. Edit /etc/php5/apache2/php.ini

$nano /etc/php5/apache2/php.ini

3. Uncomment and edit the following parts:

;opcache.enable=0 to opcache.enable=1

;opcache.memory_consumption=64 to opcache.memory_consumption=128

;opcache.max_accelerated_files=2000 to opcache.max_accelerated_files=10000

;opcache.revalidate_freq=2 to opcache.revalidate_freq=60

;opcache.fast_shutdown=0 to opcache.fast_shutdown=1

4. Save the php.ini and restart the Apache service

$sudo service apache2 restart

Enjoy your day!