How to Install Zend OPcache in Debian and Ubuntu

This article was earlier written for APC (Alternative PHP Cache), but APC is deprecated and no longer working with PHP 5.4 onwards, now you should use OPcache for better and faster performance as explained in this article…

OpCache is an advanced caching module based on opcode that works similar to other caching solutions. It significantly improves PHP performance, and your website by extension, by storing your site’s pre-compiled PHP pages in shared memory. This eliminates the need for PHP to constantly load these pages on each request by the server.

[ You might also like: 10 Top Open Source Caching Tools for Linux ]

In this guide, we will walk you through the installation of the Zend OPcache in Debian-based Linux distributions such as Ubuntu and Mint.

For demonstration purposes, we will use Ubuntu 20.04 and show you how you can install and enable the module both on Apache and Nginx web servers.

Install and Configure PHP OPcache for Apache

To set the ball rolling, launch your terminal and update your package index:

$ sudo apt update

Next, install Apache web server, PHP, and PHP modules including the php-opcache module as follows.

$ sudo apt install apache2 libapache2-mod-php php-curl php-mbstring php-opcache php-mysql php-xml php-gd

The command installs the latest Apache web server and PHP 7.4 and associated extensions. To verify the version of PHP installed, run the command:

$ php --version
Check OPcache PHP Version
Check OPcache PHP Version

The next step is to enable the OPcache caching module. Therefore, edit the php.ini configuration file.

$ sudo nano /etc/php/7.4/apache2/php.ini
$ sudo vim /etc/php/7.4/apache2/php.ini

Locate and uncomment the following lines


Save the changes and exit.

Then restart Apache to apply the changes.

$ sudo systemctl restart apache2

Finally, verify that Opcache has been enabled as follows:

$ php -i | grep opcache

The following output will be displayed on your screen.

Verify OPcache PHP Module
Verify OPcache PHP Module

This is proof enough that the Opcache module has been successfully installed.

Install and Configure PHP OPcache for Nginx

If you are planning to have Nginx as your webserver of choice and still have Opcache installed, follow the steps below.

Install Nginx, PHP, and associated PHP extensions as before.

$ sudo apt install nginx php php-fpm php-cli php-curl php-mbstring php-opcache php-mysql php-xml php-gd

Once again, confirm the PHP version installed.

$ php -v
Check OPcache PHP Version
Check OPcache PHP Version

Next, access the php.ini configuration file to enable Opcache.

$ sudo nano /etc/php/7.4/fpm/php.ini
$ sudo vim /etc/php/7.4/fpm/php.ini

As before, uncomment the following lines to enable Opcache for Nginx.


Save the changes and exit.

Then restart the Nginx web server and PHP-FPM service.

$ sudo systemctl restart nginx php7.4-fpm

Finally, confirm that Opcache was successfully installed:

$ php -i | grep opcache
Enable OPCache on Nginx
Enable OPCache on Nginx

And that was about it as far as the installation of the Zend Opcache caching module. Your feedback is most welcome.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

29 thoughts on “How to Install Zend OPcache in Debian and Ubuntu”

  1. Hi,
    Thakns for this nice tutorial.
    APC is now installed but it seems not to work : the uptime value is always 0, so I think APC is not working ! How can I check if it really caches my magento site ?
    Regards :)

  2. Hi ravi,

    I am having some problem with APC working properly. File cache always shows Hits = 1 and misses keep increasing, but at the same time, the cached file entries show some numbers in hundreds over some time.

    User cache entries shows to be working normally it seems.

    But almost twice a day i keep getting Internal server error and then have to restar php-fpm.

    I hv allocated 1024M memory and some other regular config stuff.

    If you have more idea, can i have your email ID to discuss this and send you more details about it.

    Warm rgds

  3. @katal2hod:
    First, make sure you already have these things installed on your Centos:
    make, gcc, php-devel, php-pear.
    And then, type “pecl install uploadprogress”
    You should see something like this after the installation has finished:
    Build process completed successfully
    Installing ‘/usr/lib64/php/modules/’
    install ok: channel://

    Note that I’m using Centos 64 bit, if you’re using 32 bit, then the path will show
    Installing ‘/usr/lib/php/modules/’

    Then, use “vi /etc/php.ini” (or Nano, or VIM)
    Add this line on the bottom:
    Save and close, then restart your Apache by using service httpd restart
    Done ;)

  4. @Andre Luis de Andrade:
    APC works by storing the compiled bytecode of your PHP script on the memory, so next time when a request for the same page appears, APC will provide the cached code instead of re-read and recompile the code again from your disk, thus increasing the load speed.

  5. Hello!

    OK! APC is installed and I can view the Statistics.

    And now, how APC will cache my PHP sites?

    The APC is not creating /etc/apc.* files.

    The statistics is displaying NO PHP FILES cached.

    Thanks a lot. I want to understand how APC works.


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.