Overview
Discuss WordPress and Centmin Mod Nginx on the community forums. For an alternative fastcgi_cache approach, see the WordPress fastcgi caching guide.
The WP-FFPC (Fast Full Page Cache) plugin provides an alternative WordPress caching method using Memcached server (via PHP memcache or PHP memcached) or APC Cache. All three backends are supported and installed by default on Centmin Mod.
When WP-FFPC and Nginx ngx_pagespeed module (now deprecated) were paired together, WP-FFPC handled caching while ngx_pagespeed optimised static CSS, JS, and image elements -- replacing the more complex W3 Total Cache plugin.
1. Configure MySQL for InnoDB
Ensure InnoDB is enabled in /etc/my.cnf:
innodb=ON
default-storage-engine = InnoDB
[mysqld]
character-set-server=utf8
Restart MySQL:
mysqlrestart
2. WP-CLI --allow-root
WP-CLI version 0.14+ prevents running as root user. Use --allow-root flag with all WP-CLI commands on Centmin Mod:
wp --info --allow-root
After installation, change file ownership to nginx user/group:
chown -R nginx:nginx /home/nginx/domains/yourdomain.com/public/wp
3. Installing WordPress via WP-CLI
Install WP-CLI, create the database, download and install WordPress:
# Install WP-CLI
cd /usr/local/src/centmin-v1.2.3mod/addons/
chmod +x wpcli.sh
./wpcli.sh install
# Create MySQL database
mysqladmin -u root -p create wordpressdb381
# Download and configure WordPress
cd /home/nginx/domains/yourdomain.com/public/wp
wp core download --allow-root
wp core config --dbname=wordpressdb381 --dbuser=mysqlusername --dbpass=mysqluserpassword --allow-root
# Randomise table prefix
NEWPREFIX=$(echo $RANDOM)
sed -i "s/'wp_';/'${NEWPREFIX}_';/g" wp-config.php
# Install WordPress
wp core install --url='http://yourdomain.com/wp' --title='Your Site' \
--admin_email='you@email.com' --admin_password='yourpass' \
--admin_name=adminuser --allow-root
# Set correct permissions
chown -R nginx:nginx /home/nginx/domains/yourdomain.com/public/wp
4. Install WP-FFPC Plugin
Install via WP-CLI
cd /home/nginx/domains/yourdomain.com/public/wp
wp plugin install wp-ffpc --activate --allow-root
chown -R nginx:nginx /home/nginx/domains/yourdomain.com/public/wp/wp-content/plugins/
Enable WordPress Cache
Add define('WP_CACHE',true); in wp-config.php after the DB_COLLATE line:
define('DB_COLLATE', '');
define('WP_CACHE',true);
Configure WP-FFPC Settings
- Activate via WordPress Plugins menu
- Go to Settings → WP-FFPC and select PHP Memcached backend
- Verify Memcached server address (default: 127.0.0.1:11211)
- Enable Add X-Cache-Engine header under Debug menu
- Save the settings -- without saving, caching will not be active
Create wpffpc.conf
Create /usr/local/nginx/conf/wpffpc.conf (for WordPress at root /):
# try to get result from memcached
location @memcached {
default_type text/html;
set $memcached_key data-$scheme://$host$request_uri;
set $memcached_request 1;
# avoid cache serve of POST requests
if ($request_method = POST ) {
set $memcached_request 0;
}
# avoid cache serve of wp-admin pages
if ( $uri ~ "/wp-" ) {
set $memcached_request 0;
}
if ($request_uri ~* "/(\?add-to-cart=|cart/|my-account/|checkout/|wp-admin/.*|xmlrpc\.php|wp-.*\.php|index\.php|feed/|sitemap(_index)?\.xml|[a-z0-9_-]+-sitemap([0-9]+)?\.xml)") {
set $memcached_request 0;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in|woocommerce_items_in_cart" ) {
set $memcached_request 0;
}
if ( $memcached_request = 1) {
add_header X-Cache-Engine "WP-FFPC with memcached via nginx";
memcached_pass memcached-servers;
error_page 404 = @rewrites;
}
if ( $memcached_request = 0) {
rewrite ^ /index.php?q=$request_uri last;
}
}
## rewrite rules
location @rewrites {
add_header X-Cache-Engine "";
rewrite ^ /index.php?q=$request_uri last;
}
Subdirectory install: If WordPress is at /wp, change the rewrite targets from /index.php to /wp/index.php in both @memcached and @rewrites locations.
Nginx Vhost Configuration
Add memcached upstream to /usr/local/nginx/conf/nginx.conf:
http {
# memcached servers for wp-ffpc
upstream memcached-servers {
server 127.0.0.1:11211;
}
Full vhost config (WordPress at /wp):
server {
listen 80 default_server;
server_name localhost;
root /home/nginx/domains/yourdomain.com/public;
access_log /home/nginx/domains/yourdomain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/yourdomain.com/log/error.log;
location / {
autoindex on;
}
location /wp {
include /usr/local/nginx/conf/wpsecure.conf;
include /usr/local/nginx/conf/wpnocache.conf;
try_files $uri $uri/ @memcached;
}
include /usr/local/nginx/conf/wpffpc.conf;
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
}
Restart Nginx and PHP-FPM:
nprestart
5. Verify WP-FFPC is Working
WP-FFPC only caches for guests. Log out of WordPress Admin and check for the X-Cache-Engine header:
curl -I http://yourdomain.com/wp/
# Expected response includes:
# X-Cache-Engine: WP-FFPC with memcached via PHP
Check memcached stats:
memcached-tool localhost:11211 stats
memcat --servers=localhost data-http://yourdomain.com/wp/
6. Enabling ngx_pagespeed Module (Deprecated)
Deprecated
The ngx_pagespeed module has been deprecated and removed from all Centmin Mod branches. The NGINX_PAGESPEED='y' variable no longer works. This content is retained for historical reference.
For the full install guide, see Nginx ngx_pagespeed documentation. Quick setup:
# Uncomment in your Nginx vhost:
include /usr/local/nginx/conf/pagespeed.conf;
include /usr/local/nginx/conf/pagespeedhandler.conf;
include /usr/local/nginx/conf/pagespeedstatslog.conf;
# Enable via command:
pscontrol on
# Verify:
curl -I http://yourdomain.com/wp/
# Look for: X-Page-Speed header