Hi, I am trying to figure out how to enable OPcache on my Drupal installation. According to Forum posts I read, I need to create a php.ini file with the following code:

zend_extension=php_opcache.dll
;Determines if Zend OPCache in enabled
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

I then need to upload this php.ini file into the "appropriate" directory. But which directory is the appropriate one? I am running my Drupal installation on a subdomain blog.example.com which is linked to the subdirectory www.example.com/clickandbuilds. I created the file as instructed and attempted uploading it into the home directory and into /clickandbuilds, but neither one of those worked. I'm still getting the "PHP OPcode Caching not enabled" error on my Drupal status report. How can I fix this?

If it makes a difference, I recently upgraded from Drupal 8.9.19 to Drupal 9.2.7.

Thank you for your assistance.

Comments

VM’s picture

only your host can tell you where custom php.ini files should be (assuming the host allows overriding php configuration at all). If you are on a shared host, I wouldn't venture they allow caching in memory.

"PHP OPcode Caching not enabled" - is not an error and Drupal will work fine without it. However, it will run better with it.

artiste1212’s picture

I contacted my hosting provider. They said that PHP OPcode Caching is supported but needs to be installed -- and that this needs to be done in the .htaccess file, not the php.ini file. How can I enable OPCaching in .htaccess?

VM’s picture

they should be able to tell you or point you to their documentation for accurate information. Otherwise, you use google like most of us do and test via trial and error. https://stackoverflow.com/questions/21556437/disable-opcache-temporarily

artiste1212’s picture

Thanks. Just when I thought I couldn't find anything in Google that I'm capable of understanding and adapting to my own hosting company, I found this: https://www.ionos.com/digitalguide/websites/web-development/php-7-and-op.... I'll let you know if it works.

artiste1212’s picture

As I suspected, it turns out that the technical support representative I spoke with by phone today knows even less than I do. He told me that I don't have access to php.ini and have to install OPCaching using the .htaccess file. This confused me, since none of the Google search results I found mentioned anything about .htaccess. 

It turns out that what Ionos tells its customers to do is to add a customized php.ini file specifying the changes we want to make, according to https://www.ionos.com/help/hosting/using-php-for-web-projects/changing-php-settings-in-a-phpini-file/. Then, it tells you to use an SSH command to copy that file to every subdirectory, https://www.ionos.com/help/hosting/using-php-for-web-projects/applying-php-settings-to-all-subdirectories/. I used the settings I found in https://www.ionos.com/digitalguide/websites/web-development/php-7-and-opcache-speed-up-websites/ and uploaded it according to the instructions in the other two web pages, and it's now working. PHP OPcode Caching: Enabled!