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 :
ssh -i [your-key].pem ubuntu@[ip-address]
First, check whether PHP is ready with Zend Opcache :
php -v | grep OPcache
You should get a proper output like :
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
You can find the
opcache.so extension by this command :
# step 1
sudo find / -name 'opcache.so'
Now, open this file :
# step 2
you’ll get something like :
# step 2.1
or, you can open this file :
# step 3
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 :
# step 4
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 :
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 :
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 :
Now, in case you are using HHVM, that story is newer :
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 :
php -i | grep 'Configuration File'
Better find all the
php.ini file :
You might get :
For passing in to another App, we pass can check which
php.ini is actively loaded :
php --ini | grep Loaded | cut -d" " -f12
To check all the related
php.ini you should run :
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 :
strace -o strace.log php --version && grep php.ini strace.log
If you are getting :
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 :
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 :
;; debug this
;; debug with
;; Enables opcache
;; Enables opcache cli execution like CLI cron
; debug for performance
opcache.max_wasted_percentage = 5
;; debug with value = 1
opcache.use_cwd = 0
opcache.file_update_protection = 0
opcache.revalidate_path = 0
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 :
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 :
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 :
Engine Yard, historically has a set of tools for PHP optimization :
For WordPress like cms, you should have a thing like this :
Zend Optimizer Plus is Zend Opcache Since Mid of March 2013
Zend Optimizer+ was renamed to Zend Opcache mid of March 2013. Funnily :
That has another GUI tool :
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.