Home WebServer PanelDirectAdmin Change OPcache DirectAdmin configuration

Change OPcache DirectAdmin configuration

by Thạch Phạm
Published: Last Updated on

Change OPcache DirectAdmin configuration So what is OPcache?

OPcache will save the content “precompile php code to the shared memory”. Thus, it helps to reduce the reading of PHP source code from the hard drive and recompile it every time a website is accessed.

Benefits OPcache brings:

  • Helps reduce server and VPS CPU usage.
  • Reduce TTFB (Time to first byte) for all web pages on the server.
  • Increase website loading speed.

Disadvantages of OPcache:

  • Almost no harm at all, except using a little more RAM.

If you have not installed Opcache before, you can refer to the following instructions to install it:

Step 1: Find the OPcache configuration file on the Directadmin server

OPcache’s configuration file is called opcache.ini, all configurations will be located in this. If you want to customize the configuration even more, visit the main page of php.net to see the configuration description:

The config file default path is at:

AZDIGI Tutorial

Step 2: Change the OPcache DirectAdmin configuration

To change the OPcache DirectAdmin configuration, use the following command:

AZDIGI Tutorial
vi /usr/local/directadmin/custombuild/configure/opcache/opcache.ini

Below is my configuration after changing:

AZDIGI Tutorial

Configuration explanation:

  • opcache.memory_consumption: It is the amount of RAM you will allocate to Opcache, the unit is MB. (Here I set it as 10240MB ~ 10GB for server hosting 64GB RAM)
  • opcache.interned_strings_buffer: Amount of memory used to store strings internally, in MB. This configuration command will be ignored in PHP versions lower than 5.3.0
  • opcache.max_accelerated_files: Used to control how many files PHP can hold in memory at most at once. Depending on the system you set different numbers. You can use the following command to check how many PHP files are open “find . -type f -print | grep php | wc -l” . Values that match this option are the primes {223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987..etc..}. Up to 100000 for PHP < 5.5.6, and up to 1000000 in newer versions.
  • opcache.enable_cli: Enable opcode caching for the CLI version of PHP.

If your VPS/Server has previously installed OPcache, skip step 3 and continue with step 4. If you continue to step 3, no problem.

Step 3: Rebuild Opcache to get new configuration

To build Opcache DirectAdmin, you just need to manipulate a few commands below to be successful. But only with CustomBuild 2.0.

Move to Directadmin’s build directory and change Opcache value to Yes

AZDIGI Tutorial
cd /usr/local/directadmin/custombuild
./build set opcache yes

You will get the following information (probably yes to yes if you already have opcache).

Notice returned to VPS/Server without OPcache installed:

AZDIGI Tutorial
Changed opcache option from no to yes

Step 4: Continue compiling the Opcache module with CustomBuild 2.0

Use the following command to compile Opcache:

AZDIGI Tutorial
./build opcache

Step 5: Check OPcache parameters after configuration

We have 2 methods to see the OPcache parameter that has just been changed.

Method 1: View directly on Server/VPS

To view directly on Server/VPS, we use the following command:

AZDIGI Tutorial
php -i | grep "opcache"

Here are the returned results:

AZDIGI Tutorial
[root@chelairoiahihi ~]# php -i | grep "opcache"
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => Off => Off
opcache.enable_cli => On => On
opcache.enable_file_override => On => On
opcache.error_log => no value => no value
opcache.fast_shutdown => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 320 => 320
opcache.load_comments => 1 => 1
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 1000000 => 1000000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 10240 => 10240
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 0 => 0
opcache.revalidate_path => On => On
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => On => On
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On
[root@chelairoiahihi ~]#

Method 1: View information directly with the phpinfo function

To see this way you need to create a PHP file on a certain website.

Move to a user on any website on Server/VPS. Please change your username and yourdomain to your information

AZDIGI Tutorial
cd /home/username/yourdomain/public_html/ 
vi phpinfo.php

Then insert the following php code:

Save the file and access it with the corresponding path: http://yourdomain/phpinfo.php

Thong so opcache nhin qua ham phpinfo

On your browser, use the “Ctrl + F” character search tool and search with “Zend OPcache” to get the image above.

Thus, the OPcache DirectAdmin configuration change is successful. Wishing you success.

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign