How to Install WordPress With Nginx and Redis cache on a VPS

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83

You have buy a VPS to speed up WordPress, but you are using a control panel and it's not faster than before ? In this tutorial, you will learn how to setup a Blazing fast WordPress with Nginx php7 and redis cache.
This will require to use the the command linux via SSH. Yes I know, it's less user friendly than a control panel.
But it will not require any resources after the install and we have an amazing tools to help us : EasyEngine

So, first we will talk about what we are going to install and why it will make WordPress faster.

Nginx : To pronounce Engine X”, it's the web server created in 2002, created to handle high traffic with a low memory footprint. And this is the reason which explain why Nginx is so popular at the moment. It can also be used as a reverse proxy or as a load-balancer, which means if you have few small VPS, you will be able to create a stable and reliable platform to host your website.

php7 : I will not explain what is the php but more about the difference between the 5.6 and the 7. It's the performance and there is nothing better than a small graphic to compare them. And WordPress is fully compatible with the latest version of php.

How-to-Install-WordPress-With-Nginx-and-Redis-cache-on-a-VPS.png


MariaDB
: If you haven't already used it, MariaDB is a fork of Mysql from his creator, and it's an open-source solution which is currently faster than Mysql with a lower memory and processor footprint. So no need to hesitate, if you are still using msql, even in 5.7, it's time to move !

Redis : What is Redis ? It's a remote dictionary server, which will manage your database and store the values in the memory. It's a NoSQL” solution as Redis can be used as a database by writing data on your hard drive SSD. For WordPress there is no faster solution as it will eliminate the queries to your database, and even if you are using Mariadb, it will be faster and using less resources.

But you are maybe thinking it will be very hard to configure all that stuff properly. No, you will be able to do it in less than 10 minutes ! Because we are going to use EasyEngine, the most powerful tools to create an optimized WordPress website.It's a command line tool to create install and configure a complete web server with Nginx, PHP, MariaDB and Postfix in a single command.
It also provide you the ability to manage properly your virtualhosts with Nginx and make it easy with simple command to use.

So to start you need a VPS with Ubuntu 16.04. EasyEngine is also compatible with debian 7/8 and Ubuntu 14.04.
But as EE has been build at first for ubuntu, it's the most stable solution.At first we need to install EasyEngine.
Code:
[COLOR=#555555][FONT=Lato][INDENT][SIZE=4][FONT=inherit]wget -qO ee rt.cx/ee && sudo bash ee
[/FONT][/SIZE][/INDENT]
[/FONT][/COLOR]

Done, EasyEngine is now ready to install what we need. So we are looking for WordPress with nginx, php7, redis and as it will not be harder, a SSL with let's encrypt. But you have the choice with EE :A simple website for html :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create example.com --html[/FONT]
[/SIZE][/INDENT]

A website with php :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create example.com --php
[/FONT][/SIZE][/INDENT]
A website with mysql :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create example.com --mysql[/FONT]
[/SIZE][/INDENT]

A website with SSL by let's encrypt
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create example.com --letsencrypt[/FONT]
[/SIZE][/INDENT]

And for WordPress ? You just have to choose :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create example.com --wp # install wordpress without any page caching 
ee site create example.com --w3tc # install wordpress with w3-total-cache plugin 
ee site create example.com --wpsc # install wordpress with whisp-super-cache plugin
ee site create example.com --wpfc # install wordpress + nginx fastcgi_cache 
ee site create example.com --wpredis # install wordpress + nginx redis_cache[/FONT]
[/SIZE][/INDENT]

So for my example, I will use :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site create yourwebsite.com --wpredis --letsencrypt --php7[/FONT]
[/SIZE][/INDENT]


You will have to enter Yes to the EE questions, and yes your wordpress with redis php7 and SSL is already installed and configured. You also have two plugins in WordPress :


  • [*=left]Nginx Helper to clear the cache
    [*=left]Redis Cache : To connect WordPress with Redis and to clear the cache
But you will maybe ask how you can connect to the database, what is the user of mysql and wordpress ?
You can use a custom user during the install process by using–user=admin and -pass=password to set WordPress login details.
But you can also look at the install log to find them as EE display it in the console :
Code:
[INDENT][SIZE=4][FONT=inherit]nano /var/log/ee/install.log[/FONT]
[/SIZE][/INDENT]

To see all the commands available with the websites :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site[/FONT]
[/SIZE][/INDENT]

If you want to edit some default configuration (database, user etc) :
Code:
[INDENT][SIZE=4][FONT=inherit]nano /etc/ee/ee.conf[/FONT]
[/SIZE][/INDENT]
By default EasyEngine create a backend access with all tools you can install with it (phpmyadmin, cache, php infos) at the address : http://yourserverIP:22222To secure it properly just use :
Code:
[INDENT][SIZE=4][FONT=inherit]ee secure --auth[/FONT]
[/SIZE][/INDENT]
It will ask you for a user and a password. You can edit it at anytime.To edit the default port :
Code:
[INDENT][SIZE=4][FONT=inherit]ee secure --port[/FONT]
[/SIZE][/INDENT]
And to get the mysql user of a website :
Code:
[INDENT][SIZE=4][FONT=inherit]ee site info yoursite.com[/FONT]
[/SIZE][/INDENT]
So I recommend you to change the port of admin tools, and to install what you need in the following :Adminer (phpmyadmin alternative )
Code:
[INDENT][SIZE=4][FONT=inherit]ee stack install --adminer[/FONT]
[/SIZE][/INDENT]
phpMyAdmin :
Code:
[INDENT][SIZE=4][FONT=inherit]ee stack install --phpmyadmin[/FONT]
[/SIZE][/INDENT]
phpAdminRedis (to manage data in cache) :
Code:
[INDENT][SIZE=4][FONT=inherit]ee stack install --phpredisadmin[/FONT]
[/SIZE][/INDENT]
All the Admin tools (Adminer, phpMyAdmin, phpMemcachedAdmin, FastCGI cleanup script, OPcache, Webgrind, Anemometer) :
Code:
[INDENT][SIZE=4][FONT=inherit]ee stack install --admin[/FONT]
[/SIZE][/INDENT]
You have to agree this tool is really awesome. And if you look to your memory usage using htop, you will see the difference with a control panel. Your website will be faster and you have the ability to edit your configuration or to add module when you want.So to conclude this tutorial here the links you will need to understand perfectly EasyEngine and to use it for all your setup :

You have a question ? Post a reply ;)
 

Dopani

Well-known member
Registered
Joined
Mar 11, 2014
Messages
233
Points
18
php7 : I will not explain what is the php but more about the difference between the 5.6 and the 7. It's the performance and there is nothing better than a small graphic to compare them. And WordPress is fully compatible with the latest version of php.
First off, I know that Wordpress is fully supporting php7 but for any custom sites that I am having, they didn't completely support PHP7. So it is possible to install Redis cache?

Is this guide just for Nginx? more people are using Apache then how?
 

Maxoq

Well-known member
Registered
Joined
Feb 25, 2015
Messages
520
Points
28
Great article and thanks for sharing us!

If I installed Redis cache on my VPS, can I install other caching systems like Memcached, Memcached for php, Zend OPcache or APC? or just Redis is enough for whole VPS?
 

Laurence Flynn

Well-known member
Registered
Joined
Dec 31, 2016
Messages
92
Points
8
Laurence Flynn
Old thread but found it on the forum's home page. I recently wrote a blog post that explained and simplified cached in easy to understand layman terms. Redis, like Memcached acts as a key/value data cache store (actually Redis does much more). Basically it caches DB queries and objects. Zend OpCache is a bytecode compiler that caches PHP once executed so the same PHP script doesn't have to be parsed each time. OpCache should work out the box for all PHP code and is part of PHP 7 core. Memcached (and Redis) require extra configuration in your app (e.g. WP, Joomla, Magento). Just installing Redis or Memcached does nothing.
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
First off, I know that Wordpress is fully supporting php7 but for any custom sites that I am having, they didn't completely support PHP7. So it is possible to install Redis cache?
If you don't want to use php7, you just have to not use --php7. but most of the CMS or eCommerce are running with php7 and for prestashop, magento or other big application, it's really better.

Is this guide just for Nginx? more people are using Apache then how?
Yes I know most of users a running with apache, but for a light webserver nginx is better. It just take few days to understand how it work, but just the fact it doesn't use .htaccess is a real improvment as apache have to check it for each folder it open. And if you want ot use redis, you should try nginx first.

m1small_wp35_wpsc-512x292.png


If I installed Redis cache on my VPS, can I install other caching systems like Memcached, Memcached for php, Zend OPcache or APC? or just Redis is enough for whole VPS?
With easyengine you can use a different cache for each website, but redis is more powerful than any other solution i have tested.
For any website which us a database it's really awesome. But you can try with the others too. With plesk i'm using opcache, but it"s more because I haven't integrate redis ^^
 

tlhIngan

Member
Registered
Joined
Jul 12, 2016
Messages
49
Points
8
This is a great article but I could not install it because I am using Apache on Centos 6

How to change your commands and is there a way to install Redis on Centos 6 or 7?
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
Redis can be install on Centos, but easyengine are not in love with Centos and so do I ^^

You should really try debian :lol:

More seriously have you a particular reason to use Centos ?
 

tlhIngan

Member
Registered
Joined
Jul 12, 2016
Messages
49
Points
8
tlhIngan
I found too many articles on the internet relate to Centos and it has good support while I have less guides for other OS systems.

Why easyengine doesn't like Centos and there are any same OS like Centos I can use?
 

jwn

Active member
Hosting Provider
Registered
Joined
Dec 11, 2016
Messages
65
Points
8
jwn
You can try centminmod, centmin fully compatible with centos. All function like easyengine.
 

EcommIndiaCloudIT

Member
Registered
Joined
Dec 28, 2016
Messages
64
Points
0
Quick Question:
Lets say I have a VPS server running cPanel and another cluster running Redis. Do I have to connect/point to the Redis on a cPanel level/system level or do I just point the application that wants redis directly to use the redis cluster?
 

Laurence Flynn

Well-known member
Registered
Joined
Dec 31, 2016
Messages
92
Points
8
OpCache and Redis/Memcached are totally separate and cache different things. OpCache is a bytecode caching engine. It caches executed code so it doesn't have to be parsed each time the code is called. It's the only front-end caching system you need.

I agree that Redis is better than Memcached for Magento but with WordPress they are virtually identical.
 

Laurence Flynn

Well-known member
Registered
Joined
Dec 31, 2016
Messages
92
Points
8
I found one plugin that uses Memcached SOLELY for Page Cache (Batcache).

Again, you simply don't understand caching. A Page Cache is not an Object cache. Memcached IS an object cache although it can be used to cache ANYTHING. Even in W3TC you can set Memcached as the Page Cache because it can. Redis can be an Object Cache. Memcached can be an Object Cache. I can even set Redis to Page Cache. Is Redis then only for Page Caching? C'mon man, gimme a break.
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
With W3TC, there is no reason to use Memcached only for object-cache. The proper settings will always include full-page caching using disk storage, and database caching.
I'm not trying to say if it's possible or not, I just give informations from my experience. And using memcached in 2017, doesn't make sense.
 

Laurence Flynn

Well-known member
Registered
Joined
Dec 31, 2016
Messages
92
Points
8
Your experience is obviously very limited. Sorry, not trying to be belligerent but you've got it backwards. The database cache in W3TC is redundant. The queries are already cached by MySQL's native function (query-cache). But query-cache is limited because changing a row in a database invalidates all queries to the whole database that reside in the cache. That's why you want to cache the whole result set - the objects. That's what an object cache does. It caches the result set so unaffected queries can still be pulled from the object cache. This is called "stale data" and it's one of the reasons that object caches exist.

Even EE (the basis of your thread) say the database cache in W3TC is redundant. You want a server side cache (Nginx), a full page cache and an object cache.

https://github.com/EasyEngine/easyengine/issues/509

From the author of EE:

Database Cache

Not needed IMHO. MySQL query cache is there. WordPress object-cache is also there.

Also for every wordpress request there has to be atleast one mysql connection from wp-load.php so no database cache plugin can save 100% of mysql requests.
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
VirtuBox
My experience with memcached is very limited, because I have used Varnish in the past, and Redis when it become a stable solution.
But it seems you haven't understand properly what I mean (by reading my previous post, I agree about the fact it's not the clearest answer I have wrote.)


About EE, yes the settings for W3TC are :
Code:
Page Cache: Disk Enhanced
Database Cache: Memcached
Object Cache:   Memcached
Browser Cache:   Disable
But W3TC use a full-page caching on the disk. And that mean, it require to purge the static page if there is any change on it.
In my tutorial with redis-object-cache plugin, there is no full-page caching. I can edit something on a page without having to purge each time the cache.
And the main difference between redis and memcached, is about performances to store and deliver queries.
 

WPCycle

Well-known member
Hosting Provider
Registered
Joined
Dec 31, 2016
Messages
123
Points
18
A cache argument. At least no one here mentioned caching a cache that was already cached...with a larger cache!!!!

As nonsense as that sounds...search around and you will find blog posts that basically describe how to do this...and others that will say adding too many things to an account is just a recipe to a long list of troubleshooting when things do fail.
 

eva2000

Well-known member
Registered
Joined
Jan 14, 2017
Messages
173
Points
28
Wordpress with redis caching is fast. I wrote a wordpress auto installer for my Centmin Mod LEMP stack with can choose between

1. redis nginx level full page caching
2. keycdn cache enabler for full page static caching
3. wp super cache for full pag static caching

I have a CentOS 7 + PHP 7 based demo Wordpress7 site (CentOS 7 + PHP 7) that was build with the auto installer and originally setup with WP Super cache but switched to Redis nginx level caching and it scales nicely with blitz.io 10,000 concurrent user load tests at 240-300+ million hits/day on a 2GB DigitalOcean droplet http://wordpress7.centminmod.com/232/wordpress-7-site-updates/ :)

I think folks here are confusing redis cache options, there's various redis cache options available to wordpress discussed in this thread.

1. redis object cache wp plugin is for database level
2. redis cache at nginx level leverage nginx modules ngx_http_redis and openresty nginx modules for redis2-nginx-module, srcache-nginx-module, headers-more-nginx-module and set-misc-nginx-module which are not standard out of box nginx modules included in most distros native repositories.

Both of these can be combined if you want though redis object cache can be problematic as wp-admin settings level changes might not be real-time.
 
Recommended Threads
Replies
3
Views
2,805
Replies
0
Views
1,943
Replies
15
Views
5,596
jms
Similar Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top