How to Run Redis as a Session Store for WordPress on a VPS

WordPress core barely uses PHP sessions, so most site owners never think about them. Then a store starts dropping carts or a membership plugin logs users out at random. The cause is often the same: sessions are stored as files on disk, and that setup falls apart under load or across multiple PHP workers. A redis session store wordpress setup moves those sessions into Redis, where they are fast, shared between workers, and easy to inspect. This guide walks through the whole thing on a VPS you control.

What a session store does in WordPress

A PHP session is a small bundle of temporary data tied to one visitor: a cart, a login state for a plugin, a half-finished form. PHP creates a session ID, sends it to the browser as a cookie, and keeps the data on the server, by default as files under /tmp or a similar directory.

File sessions work fine on a quiet site. They start to hurt when traffic grows. Disk reads are slower than memory reads, stale session files pile up, and if you run more than one PHP-FPM pool or a second server, a visitor can hit a worker that has no copy of their session. The result looks like a bug in the plugin. It is usually the storage.

Why a Redis Session Store WordPress Setup Beats File Sessions

People mix up the jobs Redis can do for WordPress, so separate them before you change anything. Object caching stores database query results so WordPress does less repeated work; our guide to speeding up WordPress with Redis object caching covers that setup. Page caching stores full rendered pages, which most sites hand to a dedicated page cache or a CDN instead. Session storage, the subject of this article, stores PHP session data. It does not speed up page loads directly. It makes logged-in behaviour reliable.

Before you start: what you need

You need root or sudo access on the VPS, Redis already installed or the ability to install it, and the PHP Redis extension (phpredis) for the PHP version your site runs. If Redis is not installed yet, follow our walkthrough on installing and securing Redis for WordPress first, then come back here.

Check two things before you touch any config. First, confirm which PHP version serves your site, because the extension must match it exactly. Second, confirm how much free RAM the server has. Our guide to how much RAM a VPS needs to run WordPress helps you judge whether you have headroom. A shop with a few hundred active sessions might use 50 to 100 MB; measure rather than guess.

Step 1: Install Redis and lock it down

If Redis already runs for object caching, skip to the security checks. Otherwise install it from your distribution’s packages:

sudo apt update && sudo apt install -y redis-server php8.3-redis
sudo systemctl enable --now redis-server

Use the package matching your PHP version. Then check that Redis only listens on localhost.

bind 127.0.0.1 ::1
protected-mode yes
port 6379

Set a password with requirepass in the same file. Sessions can contain login tokens, so an open Redis instance is a real risk. If your VPS has a firewall, make sure port 6379 is not exposed to the internet. Restart Redis after any change with sudo systemctl restart redis-server.

Step 2: Point PHP sessions at Redis

PHP decides where sessions live through two settings: the save handler and the save path. The redis php session save handler tells PHP to hand session data to Redis instead of writing files. Set both in your php.ini or in the PHP-FPM pool config for the site:

session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?auth=your-redis-password&database=1"

The database=1 part matters. Redis ships with 16 numbered databases, and using database 1 for sessions keeps them apart from object cache data that usually lives in database 0.

Editing the FPM pool file (/etc/php/8.3/fpm/pool.d/www.conf or your site’s pool) is usually better than editing the global php.ini, because it limits the change to one site when several share the server. Add the lines as php_value entries, then restart PHP-FPM with sudo systemctl restart php8.3-fpm, using your version number. If the save path has a typo, PHP falls back to file sessions silently in some setups, so verify the change. The test in step 4 shows how.

Step 3: Tell WordPress to use Redis sessions

Here is the part that trips people up: WordPress itself does not manage PHP sessions, so there is no switch in the dashboard. The plugins that need sessions call PHP’s session_start() directly, which means the PHP-level settings from step 2 already apply to them. For most sites, that is the whole job. A wordpress session handler redis setup is a PHP-level change, not a WordPress setting, and that distinction explains why nothing in the admin area mentions it.

There are two exceptions. First, some plugins ship their own session handling and ignore PHP’s settings entirely. WooCommerce, for example, stores cart data in its own tables and cookies rather than PHP sessions, so moving sessions to Redis will not fix a WooCommerce cart problem on its own. Check what your plugin actually uses before you blame sessions. Second, if you run WordPress behind a load balancer or on two servers, both servers must point at the same Redis instance.

Step 4: Test that sessions actually land in Redis

Log in, use a feature that relies on sessions, then check Redis from the command line:

redis-cli -a your-redis-password -n 1 keys 'PHPREDIS_SESSION*'

You should see one or more keys starting with PHPREDIS_SESSION. If the list is empty, the sessions are still going to disk. Check the active PHP-FPM pool config, confirm phpredis is loaded with php -m | grep redis for the right PHP version, and look at the PHP error log. A wrong password in the save path is the most common cause, followed by editing the config for the wrong PHP version when the server has two installed.

Also test the behaviour a visitor would notice. Log in, wait a few minutes, reload pages, and confirm you stay logged in. Then restart PHP-FPM and confirm the session survives, because Redis keeps running while PHP restarts. Sessions should outlive a PHP restart, and die only when they expire or when Redis itself restarts without persistence.

Session timeouts, persistence, and memory limits

Timeout. The wordpress redis session timeout is controlled by PHP’s session.gc_maxlifetime, in seconds. The default of 1440 seconds (24 minutes) is short for a shop where people browse slowly. Many sites raise it to 86400 seconds (24 hours) for logged-in users. Match it to how your visitors behave; a longer lifetime means more sessions held in memory at once.

Persistence. By default Redis keeps data only in memory, so a server reboot wipes every session and logs out every visitor. A redis session persistence vps setup usually relies on RDB snapshots: turn them on in redis.conf and Redis writes its data to disk on a schedule. That costs a little disk I/O, but a reboot no longer wipes every session.

Memory limit. Set maxmemory in redis.conf and pick an eviction policy that never drops sessions early. noeviction is the safe choice: when memory runs out, Redis refuses new writes instead of deleting live sessions. A failed write shows up in your logs, while a silently evicted session shows up as a confused customer. Size the limit from real usage: watch redis-cli INFO memory for a week and set the limit above the peak you observe.

Common problems and how to fix them

Random logouts after the move. Check the timeout first. If gc_maxlifetime is still at the default, sessions expire sooner than visitors expect. Also check that the object cache is not sharing the session database, because cache eviction can delete session keys.

Sessions work, then stop after a deploy. A deploy script that restarts Redis without persistence wipes sessions. Make sure RDB snapshots are enabled and that your deploy process never runs FLUSHALL, which logs out every user at once.

High memory use. Look for plugins that stuff large objects into sessions. A session should hold an ID and a few small values, not a whole product catalogue. Find the offending plugin, reduce what it stores, and set a sane maxmemory.

FAQ

Does WordPress need Redis for sessions?

Not on its own. WordPress core does not use PHP sessions. You need a session store when plugins that rely on sessions misbehave, usually under load or across multiple PHP workers.

Can I use the same Redis instance for object caching and sessions?

Yes, if you separate them with a different database number or key prefix, and keep the eviction policy safe for sessions.

What happens to sessions when Redis restarts?

Without persistence, they are gone and visitors must log in again. With RDB snapshots enabled, Redis reloads the last snapshot and most sessions survive.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.