Bobcares

How to enable Php OPcache on Ubuntu

by | Jul 18, 2022

 Php enable OPcache Ubuntu  helps to increase the speed of WordPress and PHP-based applications

Bobcares answers all questions no matter the size, as part of our server management support

Let us take a look at Enabling and configuring Php OPcache on Ubuntu.

Enabling Php Opcache on ubuntu

OPcache is a PHP interpreter Apache module. It improves performance by storing precompiled scripts in shared memory. It is commonly used to improve the performance of WordPress and PHP-based apps. The use of OPcache eliminates the need for PHP to load and parse scripts on each request.

To begin with, Php enables OPcache ubuntu, to establish an SSH connection to the server. Use the following command to open the PHP configuration file. This is the first step in enabling PHP OPcache on Ubuntu.

If the Apache module is used to interpret PHP:

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

If PHP is being interpreted by PHP-FPM or NGINX:

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

To enable the use of OPcache, simply enable the related item by changing the following line:

;opcache.enable=0 with the code gievn below

opcache.enable=1

The user must remove the; initial if it is present. And, the OPache will already be enabled at this point when restarting the web server:

Apache

$ sudo service apache2 restart

PHP-FPM / NGINX:

$ sudo service nginx restart

Create the phpinfo.php file in the folder containing the website and add the following code there to verify that OPcache is functioning properly now.

After that, save the document and open it in a browser. The presence of the OPcache section, as seen in this image, indicates that OPcache is operational.

image

RAM memory to use for Php enable OPcache on ubuntu

In this instance, the user must find the ideal balance between the RAM memory that OPCache will use and the desired speed. Since OPCache also saves the infrequently used instructions, an expanded memory doesn’t always translate into an actual performance improvement. The allocated memory will be wasted as a result, with no improvement in performance.

Note that for general use, it is advised to alter the default value (64 MegaBytes).

;opcache.memory_consumption=64 as follows, into 128 MegaBytes opcache.memory_consumption=128. The user must then increase this value by confirming the performance of the outcome.

The number of scripts to be stored

The user can specify the number of scripts to be stored in the cache in addition to the memory that is available through OPcache. Normally, this value can be left as default (2000). However, if the user’s application’s hit rate is below 100%, the user can attempt to raise it in accordance with their needs by uncommenting the following line:

;opcache.max_accelerated_files=2000 and boost the value in the following way:

opcache.max_accelerated_files=3000

The frequency of updates

The stored scripts are periodically checked for updates by OPcache. The following instruction can be changed to determine the assessment period: ;opcache_revalidate_freq = 2, as well as the default setting (in seconds): opcache_revalidate_freq = 100

Applying changes

Restart the webserver to confirm the changes.

Apache: $ sudo service apache2 restart

NGINX: $ sudo service nginx restart

OPcache will then begin to save user scripts. This is the final step in enabling php OPcache in Ubuntu.

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude it is extremely to Php enable OPcache in Ubuntu. A user can easily manage and overview the OPache and its storage usage process easily.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF