Skip to content

Website & Server Help

Menu
  • Home
  • Website
    • WordPress
    • 22 Ways To Speed-Up A Plesk Website
  • Server
    • How To Install a Let’s Encrypt SSL in Apache on Debian/Ubuntu
    • Installing Remote Desktop on Debian 12
    • Installing Remote Desktop on Ubuntu 22.04
    • MongoDB 6 with NodeJS 18 on Debian 11
    • Installing MongoDB 6 with NodeJS 18 on Ubuntu 22.04
  • Favs
    • Checking File System and Hard Drive Health
    • Running tests for a slow server or dropped packets
Menu

Troubleshooting a slow website on a Linux server, Part 3: opcode caching

Posted on January 31, 2023January 31, 2023 by admin

Enabling opcode caching using extensions like APC, XCache, or OpCache, which store the compiled version of PHP scripts in memory, allowing for faster execution. Storing compiled PHP scripts in memory significantly reduces the amount of time required to execute PHP code, improving the overall speed and performance of the website. By caching the compiled version of PHP scripts, the web server can handle more requests with the same amount of resources, reducing the overall load on the server.

To enable opcode caching using extensions like APC, XCache, or OpCache, follow these steps:

  1. Install the extension:
  • APC: pecl install apc
  • XCache: pecl install xcache
  • OpCache: included with PHP 5.5 and above, just enable opcache module in php.ini
  1. Update the php.ini file to enable the extension:
  • For APC:
extension=apc.so
apc.enabled=1
apc.shm_size=64M
  • For XCache:
extension=xcache.so
xcache.size=64M
xcache.var_size=64M
  • For OpCache:
zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
  1. Restart the web server to apply the changes.
  2. Verify that the extension is installed and working correctly by creating a PHP file with the following code:
<?php
phpinfo();
?>

And access it via a browser, search for the extension name (e.g. APC, XCache, OpCache) in the output and verify that it’s enabled and working.

  1. Adjust the size of the memory cache to best suit your server’s resources and the needs of your website.

Note: The specific steps to install and configure opcode caching extensions may vary depending on your web server and PHP setup. It’s recommended to consult the official documentation and seek professional assistance if necessary.

Cloud Server
1 vCore, 1 GB RAM, 40 GB SSD
Unlimited Bandwidth
$5/month
First month free
!