ScaleScaleScaleScale

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
zend_extension=opcache.so

; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

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

; If enabled, a fast shutdown sequence is used for the accelerated code
opcache.fast_shutdown=1

;following can be commented for production server
opcache.revalidate_freq=0
opcache.consistency_checks=1

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 https://raw.github.com/rlerdorf/opcache-status/master/opcache.php
wget https://gist.github.com/ck-on/4959032/raw/0b871b345fd6cfcd6d2be030c1f33d1ad6a475cb/ocp.php
wget https://raw.github.com/amnuts/opcache-gui/master/index.php -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
  • centos nginx install zend_extension
profile

Esteban Borges

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

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

    Find

    user = apache
    group = apache

    Change

    user = nginx
    group = nginx