When a site slows down, the database is usually the culprit: every page view runs the same dozens of queries again. Redis is one of the most popular fixes. It keeps data in RAM as key-value pairs and answers in milliseconds. This guide covers its two main jobs, sessions and caching, what to check on your hosting, and how to configure a server safely.
What Redis is and when it helps
Where MySQL stores tables on disk, Redis holds simple keys in memory, for example the home page product list under catalog:home. Each key can have a TTL and disappears when it expires, which makes Redis ideal for caches and sessions. It does not speed up every site, though. A small brochure site gains more from OPcache and page caching; Redis pays off for online stores, learning platforms and CRMs with heavy database use or many logged-in users.
Example: a store on sale day
A Tashkent appliance store announces a discount and traffic multiplies within an hour. The "best sellers" block runs a heavy multi-table query on every view, MySQL saturates and pages take 4 to 5 seconds. The list does not change every minute, so caching it for 10 minutes means one visitor triggers the query and thousands of others read the result from memory.
<?php
$r = new Redis();
$r->connect('127.0.0.1', 6379);
$r->auth('UzunVaMurakkabParol_2026');
$key = 'catalog:home';
$data = $r->get($key);
if ($data === false) {
$data = json_encode(load_products_from_mysql());
$r->setex($key, 600, $data); // kept for 10 minutes
}
$products = json_decode($data, true);
When prices change, delete the key with $r->del('catalog:home') and the next request loads fresh data.
Is Redis available on shared hosting?
It depends on the plan and server setup: some hosts give each user a private Redis process or unix socket, others offer none. First check that the PHP redis extension is enabled via phpinfo() or the control panel. Whether your plan includes Redis and which address to use can be confirmed in the sayt.uz cabinet or through support. For full control over memory and configuration, a VPS is the better fit.
Installing and securing it on a VPS
Exposed Redis servers without a password are routinely found by scanners and compromised, so lock it down right after installing.
sudo apt install redis-server php-redis
sudo systemctl enable --now redis-server
redis-cli -a 'UzunVaMurakkabParol_2026' ping # PONG
php -m | grep -i redis # redis
# /etc/redis/redis.conf (key lines)
bind 127.0.0.1 ::1
protected-mode yes
port 6379
requirepass UzunVaMurakkabParol_2026
maxmemory 256mb
maxmemory-policy volatile-lru
bind limits connections to the server itself, requirepass enforces a password, and port 6379 must stay closed in the firewall. maxmemory caps RAM so the cache cannot crowd out other services. Restart with sudo systemctl restart redis-server.
Choosing an eviction policy
allkeys-lru evicts any least recently used key, which suits a pure cache but can also evict user sessions, logging customers out or emptying carts. If sessions and cache share one instance, volatile-lru is safer because it only evicts keys with a TTL. The most reliable setup is two separate instances, since numbered databases share one memory limit.
Moving PHP sessions to Redis
; php.ini or pool config
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?auth=UzunVaMurakkabParol_2026&database=1"
Restart PHP-FPM, log in to the site and confirm that keys with the PHPREDIS_SESSION: prefix appear:
redis-cli -a 'UzunVaMurakkabParol_2026' -n 1 --scan --pattern 'PHPREDIS_SESSION:*' | head
redis-cli -a 'UzunVaMurakkabParol_2026' info memory | grep used_memory_human
WordPress and Laravel
In WordPress, add the connection constants to wp-config.php and enable the Redis Object Cache plugin. Give each site its own prefix if several share one Redis.
// wp-config.php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_PASSWORD', 'UzunVaMurakkabParol_2026');
define('WP_REDIS_DATABASE', 2);
define('WP_REDIS_PREFIX', 'misol_uz:');
Laravel supports Redis natively; update .env and run php artisan config:clear.
# .env
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=UzunVaMurakkabParol_2026
CACHE_STORE=redis # Laravel 11+ (CACHE_DRIVER in older versions)
SESSION_DRIVER=redis
Watch page load times and MySQL load for a few days afterwards. If nothing improves, the bottleneck lies elsewhere, such as heavy images or a slow external API.