Tips / Nginx

How to install PHP Zend Opcache + Cache Web Stats on Nginx

zend opcache

What are OpCode Caches?

OpCode Caches are PHP extensions that will help you to improve server & applications performance. There are many popular opcode caches like eaccelerator, xcache, apc, etc.  OpCode caches are recommended in almost all app & server production enviroments, the only thing you need is some disk or memory space in order to store the cache data.

Zend OpCode cache was originally developed by Zend, and it was a propietary software, but since PHP 5.5.x version they decided to release an open source version to be included on all major PHP versions.

Today I’m going to guide you to install Zend Opcache on EL based systems.

Installing Zend Opcache on CentOS / RHEL / Fedora

Requirements if you use CentOS/RHEL: Install EPEL repository on CentOS

yum install php-opcache

Edit the opcache.ini file:

nano -w /etc/php.d/opcache.ini

This is the basic configuration I use:

; Enable Zend OPcache extension module

; Determines if Zend OPCache is enabled

; Determines if Zend OPCache is enabled for the CLI version of PHP

; The OPcache shared memory storage size.

; The amount of memory for interned strings in Mbytes.

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.

; If enabled, a fast shutdown sequence is used for the accelerated code

;following can be commented for production server

Installing Opcache Web Stats on Nginx

One of the biggest differences with APC, is that for Zend Opcache you can find many different web stats, which will help you to understand and analyze the cache usage. We will not install the most complete stats I found so far.

Install Opcache-Status, ocp.php and opcache-gui

cd /var/www/html/
wget -O op.php

Configure Nginx to serve your opcache web stats:

nano -w /etc/nginx/conf.d/server.conf

This is the default configuration I use to serve php files from the root directory of my server using PHP-FPM with sockets, tweak as you need:

server {

    listen 80 default_server;
    access_log off;
    server_name _; 
    server_name_in_redirect off;
    root  /var/www/html;

# php-fpm configuration
        location ~ .php$ {
            root           /var/www/html;
            try_files $uri =404;
            fastcgi_pass   unix:/tmp/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 4k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;


Now load the files from your server IP:

  • http://your.server.ip/opcache.php
  • http://your.server.ip/ocp.php
  • http://your.server.ip/op.php


Popular search terms:

  • vashi-ochki ru
  • zoomhd su
  • linux install php Zend OPcache
  • installing php fastcgi and zend opcache xampp in linux

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Open and edit by command:
    vi /etc/php-fpm.d/www.conf


    user = apache
    group = apache


    user = nginx
    group = nginx