How To Install and Configure Redis on Ubuntu 16.04

I’ll show you, how to install and configure Redis on Ubuntu 16.04. Redis is an in-memory data structure store primarily used as a database and cache. Installing Redis on Ubuntu 16.04 is an easy task, just follow the steps bellow and you should install, configure and use Redis on Ubuntu 16.04.

1. Connect via SSH
Connect to your Linux server via SSH, resynchronize the package index files from their sources and install the newest versions of all packages that are currently installed on your server by using the following commands:

sudo apt-get update
sudo apt-get upgrade
Once the upgrade is completed you can move on to the next step.

2. Install Redis on Ubuntu 16.04
Installing Redis on an Ubuntu VPS is simple. Run the command below to install Redis on your machine:

sudo apt-get install redis-server
If you are planning on using Redis as an object cache for WordPress or any other PHP-based application, you need to install the following package too:

sudo apt-get install php-redis
3. Configure Redis as a cache on Ubuntu 16.04
To configure Redis as a cache you need to edit the /etc/redis/redis.conf file. We will use nano as a text editor for this purpose, but you can use any text editor of your choice.

sudo nano /etc/redis/redis.conf
To configure the max memory for Redis as well as how Redis will select what to remove when the max memory is reached, add the following lines at the end of the file:

maxmemory 128mb
maxmemory-policy allkeys-lru
In this example, Redis will remove any key according to the LRU algorithm when the max memory of 128mb is reached. Save and close the file, then restart the Redis service:

sudo systemctl restart redis-server.service
Next, enable Redis on system boot:

sudo systemctl enable redis-server.service

nginx for subfolder wordpress configuration

server {
listen      ipaddressofserver:80;
server_name xxx.xom www.xxx.com;
root        /home/username/public_html;
index       index.php index.html index.htm;
access_log  /var/log/nginx/domains/domain.xxx.com.log combined;
access_log  /var/log/nginx/domains/domain.xxx.com.bytes bytes;
error_log   /var/log/nginx/domains/domain.xxx.com.error.log error;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /subfolder{
try_files $uri $uri/ /subfolder/index.php?$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires     max;
}

location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return  404;
}

fastcgi_pass    127.0.0.1:9001;
fastcgi_index   index.php;
include         /etc/nginx/fastcgi_params;
}
}

error_page  403 /error/404.html;
error_page  404 /error/404.html;
error_page  500 502 503 504 /error/50x.html;

location /error/ {
alias   /home/username/domain.com/document_errors/;
}

location ~* “/\.(htaccess|htpasswd)$” {
deny    all;
return  404;
}

include     /etc/nginx/conf.d/phpmyadmin.inc*;
include     /etc/nginx/conf.d/phppgadmin.inc*;
include     /etc/nginx/conf.d/webmail.inc*;

include     /home/username/conf/web/nginx.domain.conf*;
}

Install vesta control panel with nginx php5-fpm mysql

Now execute the command below to download Vestacp installation file:
1.curl -O http://vestacp.com/pub/vst-install.sh

2. run below command

bash vst-install.sh –nginx yes –phpfpm yes –apache no –vsftpd yes –proftpd no –exim no –dovecot no –spamassassin no –clamav no –named yes –iptables yes –fail2ban yes –mysql yes –postgresql no –remi yes –quota no