Ends in
00
days
00
hrs
00
mins
00
secs
ENROLL NOW

🎁 Get 20% Off - Christmas Big Sale on All Practice Exams, Video Courses, and eBooks!

How to Install and Configure PHP OpCache with Web Viewer on Ubuntu 20.04

Home » BLOG » How to Install and Configure PHP OpCache with Web Viewer on Ubuntu 20.04

How to Install and Configure PHP OpCache with Web Viewer on Ubuntu 20.04

Last updated on January 2, 2024

The performance of your PHP applications can be significantly enhanced by using OpCache, a PHP opcode cache. OpCache reduces the need to recompile your PHP scripts on each request by storing the generated bytecode in memory, resulting in quicker execution rates and lessened server load.

Image retrieved from https://www.pinterest.ph/pin/flash-running-poster-custom-posters-design-your-own-wall-art-create-personalized-prints–792281759458556733/

This article will walk you through installing and configuring PHP OpCache with Web Viewer on Ubuntu 20.04.

Install OpCache

Install the Nginx, PHP, and additional PHP extensions with the following command:

sudo -i
apt-get install nginx php php-fpm php-cli php-OpCache php-mysql php-zip php-gd php-mbstring php-curl php-xml -y

After installing, use the following command to check if the OpCache was successfully installed.

php -version

Configure OpCache

Once OpCache is installed, you can configure it by editing the php.ini file.

cd /etc/php/7.4/fpm
sudo vi php.ini

Here’s an example configuration file:

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60

Let’s go through each configuration one by one:

  • opcache.enable: Opcache may be enabled or disabled using this directive. Set it to 1 to turn on OpCache.

  • Tutorials dojo strip
  • opcache.memory_consumption: This directive specifies how much memory opcache may utilize to cache bytecode. The default amount is 64MB. However, if you have adequate RAM, you can raise it.

  • opcache.max_accelerated_files: This directive specifies how many PHP scripts opcache may cache. The default amount is 2000. However, if you have a huge number of PHP scripts, you may raise it.

  • opcache.revalidate_freq: This directive specifies how frequently opcache checks to see whether a script has been changed. The default number is 2 seconds, but you may raise it if you don’t need to monitor for changes on a regular basis.

Enable Web Viewer

The visual viewer provides information on the performance of your OpCache. To activate the Web Viewer, copy the code below.

Replace the “your_domain” with the correct directory name.

cd /var/www/your_domain/
sudo wget https://raw.githubusercontent.com/rlerdorf/opcache-status/master/opcache.php

Conclusion

That’s all! It is good to enable OpCache as it will speed up your PHP website. You can verify the installation by typing your_domain.com/opcache.php on the web browser.

After OpCache is enabled, you may check its status on the opcache status page to see how it is doing. The opcache status page gives details on how much memory is being utilized by the opcache, including how much memory is free, wasted, and how many hits and misses there were.

The definitions of each metric are as follows:

  • Used: The amount of memory that opcache is presently using.

  • Free: The amount of memory that can be used by opcache.

  • Wasted: Memory that has been allotted to scripts that are no longer needed.

  • Hits: The quantity of times an opcache cached script was served.

  • Misses: The quantity of times a script needed to be recompiled because the opcache cache didn’t include it.

A high hit rate and a low miss rate indicate that opcache is being used appropriately. If you notice a large number of hits and a low number of misses, this indicates that opcache is effectively caching your PHP scripts and that your website is benefiting from the enhanced performance. Furthermore, if the quantity of memory wasted is minimal, this indicates that opcache is managing memory efficiently and not allocating memory to scripts that are no longer in use.

Get 20% Off – Christmas Big Sale on All Practice Exams, Video Courses, and eBooks!

Tutorials Dojo portal

Learn AWS with our PlayCloud Hands-On Labs

Tutorials Dojo Exam Study Guide eBooks

tutorials dojo study guide eBook

FREE AWS Exam Readiness Digital Courses

FREE AWS, Azure, GCP Practice Test Samplers

Subscribe to our YouTube Channel

Tutorials Dojo YouTube Channel

Follow Us On Linkedin

Recent Posts

Written by: Nestor Mayagma Jr.

Nestor is a cloud engineer and member of the AWS Community Builder. He continuously strives to expand his knowledge and expertise in AWS to foster personal and professional growth. He also shares his insights with the community through numerous AWS blogs, highlighting his commitment to Cloud Computing technology. In his leisure time, he indulges in playing FPS and other online games.

AWS, Azure, and GCP Certifications are consistently among the top-paying IT certifications in the world, considering that most companies have now shifted to the cloud. Earn over $150,000 per year with an AWS, Azure, or GCP certification!

Follow us on LinkedIn, YouTube, Facebook, or join our Slack study group. More importantly, answer as many practice exams as you can to help increase your chances of passing your certification exams on your first try!

View Our AWS, Azure, and GCP Exam Reviewers Check out our FREE courses

Our Community

~98%
passing rate
Around 95-98% of our students pass the AWS Certification exams after training with our courses.
200k+
students
Over 200k enrollees choose Tutorials Dojo in preparing for their AWS Certification exams.
~4.8
ratings
Our courses are highly rated by our enrollees from all over the world.

What our students say about us?