How to enable fastcgi cache on Cloudpanel to speed up WordPress. Cloudpanel is fast and a free control panel on Debian with Nginx and MySQL. By enabling fastcgi cache WordPress websites become even faster on this super fast and lightweight server stack with free control panel.
Cloudpanel
Cloudpanel is a free control panel for PHP, in use by millions of web servers around the world. Currently of version 1.06 it is based on Debian 10, Nginx, Percona MySQL and Redis. Right out of the box this is a super fast and lightweight web server stack for WordPress and other apps.
How to enable fastcgi cache on Cloudpanel
- Add those lines to the top of your Vhost config file with the Vhost editor.
*Change HAJHU to your APPNAME
fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_path /dev/shm/fastcgi-cache levels=1:2 keys_zone=HAJHU:100m inactive=60m; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
*If you are planning to use it on multiple/all websites than edit the main Nginx configuration file and add it to the http section. Purging one site will result in purging all websites, I don’t think this is recommended.
Log in via SSH:
sudo nano /etc/nginx/nginx.conf
2. Login via SSH and make a directory:
mkdir /dev/shm/fastcgi-cache
3. add those lines to the fastcgi location block in the Vhost editor:
fastcgi_cache HAJHU; fastcgi_cache_valid 200 60m; add_header Cache-Control max-age=0; add_header Nginx-Cache "$upstream_cache_status"; add_header Last-Modified $date_gmt;
4. Add those lines above the fastcgi block in the Vhost editor:
set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; }
5. Install and configure the Nginx Helper plugin.
In settings turn on: enable purge and enable delete local server cache files
6. Edit your wp-config.php file and add the following line:
define('RT_WP_NGINX_HELPER_CACHE_PATH', '/dev/shm/fastcgi-cache');
7. Install the http-cache-purge
module, log in via SSH:
sudo apt install libnginx-mod-http-cache-purge
8. add those lines to the Vhost file under the fastcgi location block:
*change your server ip address
location ~ /purge(/.*) { allow 127.0.0.1; allow "change_to_your_server_ip"; deny all; fastcgi_cache_purge HAJHU "$scheme$request_method$host$1"; }
Conclusion
I have tested some websites, some faster and slower sites and all sites showed drastic performance improvements. Sites that loads in 1.5 second now loads in 0.6 seconds. This is crazy, so fast. It really depends per website how much performance improvements one can make. Generally the tests showed that websites loads twice as fast and other very fast loading websites just loads about 200 millisecond faster.
I also tested with a normal caching plugin enabled and disabled. Both has good performance but with normal caching enabled (caching the cache) it tends to be just a bit faster.
This is a perfect solution for everybody with just 1 WordPress Website on a VPS with Nginx. Fastcgi Cache gives just that extra performance boost to let the site load just a little bit faster.
More interesting articles:
- How to install CloudPanel with NGINX and MySQL to host WordPress websites
- How to speed up WordPress
- How to speed up WordPress with WP Super Cache & NGINX rules
- WooCommerce and Nginx’s fastcgi_cache