WordPress object cache is a common way to speed up your site. PHP-APCu on Ubuntu 16.04 can help achieve your goal of supreme WordPress or WooCommerce speed.
This guide will show you how to install APCu Object Cache for PHP7 for WordPress on Ubuntu 16.04. There are three installation methods outlined here to best suit your needs. Usually installing from the repository or using PEAR is recommended, for bleeding edge users installing APCu from source it shown as well.
Install APCu Object Cache for PHP7 on WordPress on Ubuntu 16.04
Here are 3 ways to install the APCu object cache for WordPress or WooCommerce.
You should only choose one installation method.
- Install APCu object cache for WordPress with one of the following methods
- Then install the APCu WordPress object cache plugin
Install APCu Object Cache via Repository
Using this method you will not always get the latest version, it is however the easiest method.
Restart your php7.0-fpm service if you are using nginx
Reload Apache if you are using it.
Install APCu Using php PEAR
Another way to install is using php-pear, install it first
Running this command will install APCu.
Add the extension to a custom ini file.
Since I use php7.0-fpm with nginx I am symlinking into the php7.0 fpm and cli folders.
Restart php7-fpm
Apache2 users will want to symlink this file
Apache users reload the Apache service
Install APCu from Source Manually
The last way to install php7-apcu is to build from source. This way you get the bleeding edge version.
We need to install the php 7 development package and git first.
Enter your /tmp folder and clone the latest APCu source code from the git repository.
Now build the php7.0-apcu extension and install it.
Add the extension to the apcu.ini
file
Since I use php7.0-fpm with nginx I am symlinking into the php-7.0 fpm and cli folders.
Restart php7.0-fpm service
Apache2 users will want to symlink this file
Reload the Apache service
Install the APCu object cache plugin
We are going to install the LCache Plugin hosted on github sponsored by Pantheon.
If you do not have WP-CLI or shell access to your host then you have to create the object-cache.php file manually with these instructions.
You will see this output
Now you can optionally adjust the RAM for APCu and monitor the APCu cache
Adjust PHP-APCu RAM
Open the apcu.ini
configuration file
Add the apc.shm_size
line after the extension
line. Here the APCu allocated ram is being changed to 50 MB.
Ctrl+X, Y and Enter to Save
Restart php7.0-fpm if you are using nginx or Apache with FPM.
Reload Apache if that is your web server of choice
Monitoring APCu Cache
Download the apc.php script
Now you can open yourdomain.com/apc.php and see the amount of cached objects, hit and miss rate.
Sources
Using PHP7 with APCu and W3 Total Cache
Krakjoe APCu Monitoring
Control Panel for APCu
I’ve installed this on two sites – both on their own VPSs in Digital Ocean, and in both cases we’ve had things disappear from the back end of wordpress – widgets, shortcodes, and other configuration type things.
You wouldn’t think its related, but wp-lcache is the only thing common to these two sites.
Ever heard of something like this?
Hi Simon, that is unfortunately quite common with object cache which sometimes can have these random side effects. It is usually a plugin or theme not using transients correctly, compatibility issue with the plugin or just a fault of the object-cache possible in WordPress
Holy moly.
Unfortunately this does happen, although very rarely once a site has been setup and running for some time. It’s not usually a major issue though. As @blindpet:disqus indicates it’s usually a case of the data being held in cache but getting dropped before it gets written to the database.
In my experience the best solution is to not turn on your object caching until the site has been fully developed and deployed. This way you a limiting the potential for crucial data to be lost along the long.
hello
is this any better than Redis Object cache?
not
Thanks for sharing @JdMnT:disqus but unfortunately ownCloud don’t seem to offer any evidence for their claim
so please take with a grain of salt
Thank you! Very helpful!
The option with build from Source code help me and didn’t take a lot of time.
Hello thanks for article.
You says: “apc.shm_size = “50M””
but 32mb appears in the picture. I did 512mb too. I restarted my server. however, it still looks 32mb.?
Regards