Here is Full Guide to Zend Opcache Optimization for Nginx PHP5-FPM for Ubuntu Server Running on HP Cloud. We Suggest to Use Zend Opcache over APC. Most of Our Guides, like installing Nginx-PHP5-FPM on Rackspace Cloud, installing Nginx-PHP5-FPM on HP Cloud, installing Nginx-PHP5-HHVM on HP Cloud – we already have prepared the installation ready and running with PHP Zend Opcache. So, for this guide on Zend Opcache Optimization for Nginx Ubuntu (HP Cloud); we will not repeat the initial steps for the preparation phase. OPcache is designed to replace the APC module.
Zend Opcache Optimization for Nginx Ubuntu : Use OpenStack Snapshot for HP Cloud and Rackspace
OpenStack has the Snapshot feature named OpenStack Raksha for HP Cloud and Rackspace. Thus you can keep a live website’s working copy and do these tests on that dev setup spend from Snapshot. It is not exactly hugely risky, but we prefer not to work with a live server.
Preparation For Zend Opcache Optimization for Nginx Ubuntu (HP Cloud)
SSH to the instance :
---
1 | ssh -i [your-key].pem ubuntu@[ip-address] |
First, check whether PHP is ready with Zend Opcache :
1 | php -v | grep OPcache |
You should get a proper output like :
1 | with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies |
You can find the opcache.so
extension by this command :
1 2 | # step 1 sudo find / -name 'opcache.so' |
Now, open this file :
1 2 | # step 2 /etc/php5/mods-available/opcache.ini |
you’ll get something like :
1 2 | # step 2.1 /usr/lib/php5/20121212/opcache.so |
or, you can open this file :
1 2 | # step 3 nano /etc/php5/fpm/conf.d/05-opcache.ini |
This is when we are using PHP5-FPM. If you want to do these for HHVM with PHP5-FPM fallback, you need to work with loaded php.ini
file directly. For step 2
way, you need to debug this line on /etc/php5/mods-available/opcache.ini
with these :
1 2 3 | # step 4 zend_extension=/usr/lib/php5/20121212/opcache.so # zend_extension=opcache.ini |
That zend_extension=opcache.so
versus zend_extension=/usr/lib/php5/20121212/opcache.so
has some bug adding those after hundreds of security patches to stop spyware activities! In short, you need to confirm whether Zend Opcache is working or not! Here is a nice OpCache GUI tool’s instruction guide :
1 | https://github.com/PeeHaa/OpCacheGUI/wiki/Installation |
It is a bit difficult for the new users. There are easy simple files but they will need some HTTP based protection, else all can vie them. See this fool’s file :
1 | http://pryormedia.net/opcache.php |
Do not report to the webmaster! If you keep your opcache.php
in this way, anyone can hack! If you are the fool (forgive me!), then block the access either by modifying the PHP file or Nginx config file. Or you can add some adverts on it! It has been indexed by Google with good SERP!
This is better tool as it is CLI based :
1 | http://gordalina.github.io/cachetool/ |
Now, in case you are using HHVM, that story is newer :
1 | http://docs.hhvm.com/manual/en/ref.opcache.php |
From various tests, nicely optimized HHVM with Opcache server can give over 15 times better performance than non optimized. Basically you need to work in a bit dirty way, you need to find the loaded php.ini
file directly. It may not be the php.ini
file :
1 | php -i | grep 'Configuration File' |
Better find all the php.ini
file :
1 | locate php.ini |
You might get :
1 2 3 4 5 6 7 8 9 | /etc/hhvm/php.ini /etc/php5/cgi/php.ini /etc/php5/cli/php.ini /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.save /etc/php5/fpm/php.ini.save.1 /usr/share/php5/php.ini-development /usr/share/php5/php.ini-production /usr/share/php5/php.ini-production.cli |
For passing in to another App, we pass can check which php.ini
is actively loaded :
1 | php --ini | grep Loaded | cut -d" " -f12 |
To check all the related php.ini
you should run :
1 | php -i | grep "\.ini" |
Yeah, it can happen, if you optimize only one file, you’ll not get 100% work. There should be no problem to edit the main file first and then add the needed block of code on all the related php.ini
for fail-proof system.
We have not said the all! Run this :
1 | strace -o strace.log php --version && grep php.ini strace.log |
If you are getting :
1 | open("/usr/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory) |
then create the path, copy the loaded php.ini
there and properly chmod
it. PHP is more bad with more difficult setup to optimize to make it somewhat faster. For that reason, some symlinks in this way :
1 | ln -s /etc/php5/php.ini php.ini |
Core Configuration For Zend Opcache Optimization for Nginx Ubuntu (HP Cloud)
So far, we have only prepared the server instance for Zend Opcache optimization for Nginx running on Ubuntu.
Basic Settings :
Basic Zend Opcache Optimization for Nginx Ubuntu is This :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ;; debug this zend_extension=/usr/lib/php5/20121212/opcache.so ;; debug with ; zend_extension=opcache.so ;; Enables opcache ; opcache.enable=0 opcache.enable=1 ;; Enables opcache cli execution like CLI cron opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.validate_timestamps=0 opcache.fast_shutdown=1 ; debug for performance opcache.consistency_checks=1 opcache.max_wasted_percentage = 5 ;; debug with value = 1 opcache.use_cwd = 0 opcache.file_update_protection = 0 opcache.revalidate_path = 0 ;; debug opcache.inherited_hack = 1 opcache.max_file_size = 0 opcache.log_verbosity_level = 2 opcache.preferred_memory_model = "" ; opcache.error_log = "" ;; Empty string assumes stderr, you should create the path and chmod opcache.error_log = "/var/log/error/opcache.log" ;; make sure we have not repeated anything ;; remove the commented out lines |
Obviously, run :
1 2 3 | service php5-fpm restart service hhvm restart service restart restart |
depending on your setup. This is a basic optimization. This can go like this with more :
1 2 3 4 5 6 7 | opcache.use_cwd = 1 opcache.validate_timestamps = 1 opcache.save_comments = 1 opcache.enable_file_override = 0 opcache.revalidate_path = 1 opcache.load_comments = 0 opcache.blacklist_filename string = /var/www/broken.php |
The list is endless :
1 | http://php.net/manual/en/opcache.configuration.php |
Engine Yard, historically has a set of tools for PHP optimization :
1 | https://github.com/engineyard/ey-php-performance-tools |
For WordPress like cms, you should have a thing like this :
1 | https://wordpress.org/plugins/opcache/ |
Zend Optimizer Plus is Zend Opcache Since Mid of March 2013
Zend Optimizer+ was renamed to Zend Opcache mid of March 2013. Funnily :
1 | https://github.com/zendtech/ZendOptimizerPlus |
That has another GUI tool :
1 | https://gist.github.com/ck-on/4959032 |
Zend Optimizer, unlike Zend Opcache doesn’t load files encoded by Zend Guard. Zend provides another component.
Keep it in mind – do not use both XCache and Opcache. Dual caching will frankly, waste the memory. Zend Optimizer does not work properly with WordPress based websites. XCache is always the best for very good setup, specially physical one with caching by Akamai for page delivery. For virtual servers, cloud servers with less than 16 GB RAM and unknown virtualization software, Opcache works better. XCache works great with a real physical memory. Only Windows Cache can beat XCache. But, XCache has many smaller issues which can be costly for a WordPress setup. Practical fact about WordPress is that, without W3TC and Nginx caching system, HHVM, WordPress can not be served faster like Python. Opcache is better option for the most common virtual setups.
Tagged With opcache