Introdução
Opcache é um módulo do apache usado para aumentar a aumentar a velocidade das ações. Ele armazena scripts pré-compiladas em um espaço da memória.
Aqui usaremos o Debian 10 mas pode ser feito em qualquer outra distro, basta ter o apache instalado.
A versão do php usada aqui é a 7.3.19:
elder@debian:~$ php -version PHP 7.3.19-1~deb10u1 (cli) (built: Jul 5 2020 06:46:45) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.19-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies
Instalando o Módulo
Veja se o módulo já não está instalado.
elder@debian:~$ php -m | grep -i opcache Zend OPcache Zend OPcache
Se não aparecer nenhum resultado então precisará instalar o módulo opcache com o comando abaixo:
elder@debian:~$ apt-get install php-opcache -y
Editando o Arquivo php.ini
Agora edite o php.ini com seu editor de texto preferido. Usarei o vim mas poderia usar o nano ou outro qualquer.
Descomente as linhas abaixo retirando os ; no início de cada.
elder@ocschat:~$ sudo vim /etc/php/7.3/apache2/php.ini ... opcache.enable=1 opcache.memory_consumption=128 opcache.max_accelerated_files=10000 opcache.revalidate_freq=200 ....
Reinicie o Apache
elder@ocschat:~$ sudo systemctl restart apache2.service
Verificando
Podemos validar com o seguinte comando:
elder@ocschat:~$ php -i | grep -i opcache /etc/php/7.3/cli/conf.d/10-opcache.ini, with Zend OPcache v7.3.19-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies Zend OPcache opcache.blacklist_filename => no value => no value opcache.consistency_checks => 0 => 0 opcache.dups_fix => Off => Off opcache.enable => On => On opcache.enable_cli => Off => Off opcache.enable_file_override => Off => Off opcache.error_log => no value => no value opcache.file_cache => no value => no value opcache.file_cache_consistency_checks => On => On opcache.file_cache_only => Off => Off opcache.file_update_protection => 2 => 2 opcache.force_restart_timeout => 180 => 180 opcache.huge_code_pages => Off => Off opcache.interned_strings_buffer => 8 => 8 opcache.lockfile_path => /tmp => /tmp opcache.log_verbosity_level => 1 => 1 opcache.max_accelerated_files => 10000 => 10000 opcache.max_file_size => 0 => 0 opcache.max_wasted_percentage => 5 => 5 opcache.memory_consumption => 128 => 128 opcache.opt_debug_level => 0 => 0 opcache.optimization_level => 0x7FFEBFFF => 0x7FFEBFFF opcache.preferred_memory_model => no value => no value opcache.protect_memory => Off => Off opcache.restrict_api => no value => no value opcache.revalidate_freq => 2 => 2 opcache.revalidate_path => Off => Off opcache.save_comments => On => On opcache.use_cwd => On => On opcache.validate_permission => Off => Off opcache.validate_root => Off => Off opcache.validate_timestamps => On => On