Moodle Redis session handler setup

Moving Moodle sessions to Redis lets every web node read and write the same session store. This page covers the settings, topology, lock behavior and checks that decide whether the change holds under load.

On this page

When a Moodle Redis session handler is worth the change

Move sessions to Redis when your Moodle cluster already runs more than one web node and session storage, whether files or the database, is what limits how you scale. With file sessions, every web node must see the same session directory, which pushes you toward shared storage or sticky routing. With database sessions, every page request adds load to the database that also serves courses, quizzes and reports. The Redis session handler, configured through the session_redis settings in config.php, stores session data in a Redis server that all web nodes reach over the network. Any node can then answer any request, and session traffic leaves the database and shared file systems. This page assumes you already operate multiple web nodes, so the question is whether Redis is the right shared store for your sessions, not whether you need a cluster at all.

The change moves where sessions live, not how Moodle locks them. Moodle still takes a session lock for each request that writes to the session, so two concurrent requests from the same user can still queue behind each other. Redis removes storage bottlenecks, but it will not fix slow pages caused by long-running requests holding that lock. Before you commit, profile your current session lock warnings and identify which pages hold locks longest. Pages that only read session data may be candidates for read-only sessions, which are covered in a later section of this page. Also plan for what happens if Redis is unavailable, because sessions stored only there will be lost on failure unless you design persistence and failover deliberately.

Confirm the exact session_redis keys, their defaults and the supported options against the Moodle documentation for your target release before you write configuration. The minimum PHP version differs by release: Moodle 5.1 requires 64-bit PHP 8.2 or later, and Moodle 5.3 requires 64-bit PHP 8.3 or later, so check your PHP build and the Redis PHP extension before choosing the target. Ask your platform team to confirm whether your Redis service is a single instance, a replicated pair or a managed offering, and who owns its patching, memory limits and network access rules. The effort depends on how many web nodes, environments and sessions you run, and on how much of your current session behavior you have measured, so a written scope should state these inputs explicitly.

How web nodes share one session store in Redis

The flow starts at the load balancer, which sends each request to one of the Moodle web nodes. Each node opens the session in the shared Redis service, takes the session lock for the duration of a write-capable request, and releases it before the response returns. Read-only pages skip the lock, so they can run in parallel. The database and the shared dataroot sit outside the session path and should be checked separately. Treat the Redis box as a trust boundary: restrict network access, require authentication and encrypt the connection where the deployment allows it.

Web nodes share sessions through one Redis service, with the database and dataroot kept separate.

Moodle Redis session handler options and when each fits

This table compares the main session_redis settings, what each controls, when a team would change it, and the trade-off involved. Use it as a checklist for planning, then confirm exact key names, accepted values and defaults in the Moodle documentation for the release you are deploying. The main takeaway is that most settings matter only once several web nodes share one Redis service.

Setting areaWhat it controlsWhen to change it and trade-off
Host or hostsWhich Redis server or servers Moodle connects to for session storageA single host suits one site with one Redis instance. Multiple hosts let Moodle use a list of servers, but confirm the failover and selection behavior for your release before relying on it.
Port and database selectionThe network port and the Redis logical database holding Moodle sessionsSeparate database numbers keep sessions apart from cache data on a shared Redis. Sharing one instance across unrelated applications raises the risk of key collisions and noisy neighbors.
AuthenticationWhether Moodle presents a password or other credential to RedisEnable it whenever Redis is reachable from more than one host. Confirm the exact setting name and how the password is stored in config.php for your version.
TLSWhether the connection to Redis is encrypted in transitUse TLS when session traffic crosses a network segment you do not fully control or when your security baseline requires encryption between services. The cost is certificate management and some extra connection overhead.
Lock timeout and retryHow long a request waits for a session lock and how often it retriesRaise the timeout only after profiling shows contention. A longer wait hides slow requests and can pile up PHP workers during peak load.
Lock warning behaviorWhether Moodle logs a warning when a session lock is held too longKeep warnings on in test and load environments to find slow pages. Warnings add log volume, so review the log destination before a busy term.
Serializer and compressionHow session data is encoded and whether it is compressed before storageCompression reduces memory for large sessions but adds CPU work per request. Test the chosen serializer with your installed plugins, since some plugin data may not round-trip cleanly.
Read-only sessionsWhether a page opens the session without taking a write lockSuitable for pages that only read session data, such as some AJAX or status endpoints. Pages that change session state must keep the write lock, so confirm each page's behavior in profiling before enabling it widely.

Single host, multiple hosts and TLS: choosing the Redis topology

A single Redis host is the simplest topology for Moodle sessions. Every web node points at one address, so configuration is short and there is nothing to elect or fail over. The trade-off is that the host is a single point of failure: if it stops, active sessions are lost and users are signed out, and Moodle has no second copy to fall back to. For a lab, a pilot or a small site where a forced sign-in is an acceptable outcome, this is usually reasonable.

  • Session loss on restart: Stopping or restarting the host drops every stored session unless persistence is configured, so plan for users to sign in again.
  • Client reconnection: Moodle reconnects on its next request once the host is back, but in-flight requests during the outage will fail.
  • Memory headroom: Confirm the host has enough memory for the expected session count and set an eviction policy you have tested, so sessions are not evicted silently.
  • Network exposure: Keep the host on a private segment reachable only from web nodes, with authentication enabled on the Redis instance.
  • Upgrade path: Moving to a replicated topology later changes the connection settings, so keep host names in configuration rather than in code.

Before you choose this tab, confirm with your Redis platform team what persistence and eviction behavior the host uses and how sign-out during a restart will be communicated to users.

How session locks and lock warnings affect page speed

Moodle holds a session lock for the length of any request that writes to the session, and other requests from the same user wait behind it. A learner who opens several course pages at once, or a teacher whose browser fires background calls while a slow report loads, can end up with requests queued one after another even though the database and web nodes are idle. With Redis as the session store, the lock is a key in Redis, so the queue is a property of how Moodle requests are structured, not of the Redis server's speed. Moving sessions to Redis does not remove this behavior, and a fast Redis host can make the problem look like a web tier issue when it is really a long-running request holding the lock.

The lock_timeout and lock_warning_timeout settings in the session_redis configuration decide how the queue shows up. The timeout is how long a request waits for the lock before giving up, and the warning threshold is when Moodle logs that a request has waited unusually long. Warnings are the signal to act on: each one points to a request that either ran long while holding the lock or was blocked by one that did. Raising the timeout so that waits never fail does not make the underlying request faster. It only lets the queue grow, which moves the symptom from visible errors to slower pages and higher PHP worker occupancy under load.

Before changing either value, collect the warnings alongside evidence from the profiling admin tool and the performance report. Match each warning's time and user with the slow page in the profile, check whether the request is a known long task such as a large report, a bulk enrolment or an import, and decide whether the fix is in the code path, the schedule or the session design. Confirm with your Moodle version's documentation which session settings and warning behaviors apply to your release. Only after the slow requests are understood should the timeout be adjusted, and the reason should be written down so the next team can see why the value was set.

Serializer, compression and read-only sessions: decisions to test

The session_redis settings that change how Moodle reads and writes session data are coupled: the serializer affects size and PHP compatibility, compression trades CPU for memory, and read-only sessions reduce lock contention on pages that never write. Test each change against a representative page set before it reaches production, and plan for how existing sessions respond during rollout.

Choose the serializer against your PHP version

The serializer determines how session data is encoded in Redis, and it must match what your PHP build supports. Confirm the serializer options available in your PHP and Moodle versions before setting them in config.php. Then test a login, a course view and a quiz attempt on a staging cluster with the chosen serializer, checking that session values survive a page change and a logout. Record the serializer in your change log, because switching it later invalidates the stored data.

Minimum PHP version
8.2
Moodle 5.1 notes

Decide whether to compress session data

Compression reduces the memory Redis uses for each session but adds CPU work on every session read and write. The useful question is whether memory pressure on the Redis host is real for your concurrent user count, or whether it is a guess. Measure Redis memory use and PHP worker CPU during a simulated peak using your own page mix, then compare the two runs. If the web tier is already CPU-bound, compression is likely the wrong trade.

Use read-only sessions where pages never write

Pages that only display data, such as course listings or read-only reports, do not need to hold the session lock. Moodle lets these pages open the session read-only so concurrent requests from the same user do not queue behind one another. Build a list of the pages that do not write to $SESSION, then confirm each in code review. Measure lock wait time on that page set before and after the change, and check the session lock warnings in the logs for the pages you expected to improve.

Test lock timeouts and warnings together

Lock timeout and lock warning settings decide how long a request waits for a session lock before it fails or logs a warning. Set them too low and users see errors during slow requests, too high and stuck requests hold workers. Run a load test with a deliberately slow page mixed into normal traffic, then review the warnings and timeouts it produces. Adjust the values only after you see which pages wait, and document the final values with the test results.

Plan the rollout for existing sessions

Changing the serializer, compression or lock settings can make sessions written under the old settings unreadable, which signs users out or produces errors on their next request. Decide whether to schedule the change in a low-traffic window, drain sessions, or accept forced logins. Confirm the behavior on a copy of production session data, and prepare a rollback that restores the previous settings without losing the Redis instance. Ask your Moodle partner or internal team to write this down before the change window opens.

Moodle Redis session handler setup, step by step

This sequence moves Moodle sessions from the default store to Redis in a controlled order, so each change is checked on a staging copy and a single node before a second web node relies on the shared session store.

  1. Confirm release, PHP and Redis extension support

    Confirm the Moodle release you run, the PHP version it requires and that the PHP Redis extension is installed and loaded on every web node. Check the Moodle release notes for the version you run, since minimum PHP and database versions change between releases. For example, Moodle 5.1 requires 64-bit PHP 8.2 or later and Moodle 5.3 requires 64-bit PHP 8.3 or later. Record the PHP version, the extension version and the Moodle build in a change ticket. Done when php -m on each node lists the Redis extension and the Moodle administration page shows no failed environment checks.

  2. Provision Redis with authentication and network limits

    Provision the Redis server or cluster in the same network segment as the Moodle web nodes, with a password or ACL user required for connections. Bind Redis only to internal interfaces, restrict inbound access to the web node addresses with a firewall or security group, and enable TLS if traffic crosses a network boundary your policy does not trust. Confirm the security settings against current Redis documentation for your version, since defaults vary. Done when a connection from an allowed web node succeeds with credentials, and a connection from any other host is refused.

  3. Set session handler in a staging copy

    In a staging copy of config.php, set the session handler to Redis and add the session_redis settings: the host or hosts, port, authentication, database number and any TLS options your Redis deployment requires. Keep the production file untouched until the test passes. Set the session lock timeout and lock expiry values deliberately rather than leaving defaults untested, and review the Moodle session documentation for the keys your release supports. Done when the staging site starts, the administration page loads and the config file passes a PHP syntax check with php -l config.php.

  4. Run a single-node test

    Point one staging web node at the Redis store and test sign-in, page navigation, a quiz attempt and a file upload as a test user. Watch the Redis server for new keys with the session prefix and check the Moodle logs for session errors. Confirm that concurrent AJAX requests from one browser tab do not stall for long periods. Done when a login persists across page loads, the session keys appear in Redis with expected expiry values, and the web server and Moodle logs show no session connection errors during the test window.

  5. Roll out to a second node with session check

    Add the second web node with the same Redis settings and confirm both nodes read the same session data. Sign in on node one, then send requests through the load balancer that land on node two, and confirm the user stays signed in without a sticky session if your design relies on shared sessions. If your design uses stickiness instead, confirm the load balancer keeps each user on one node and that a failover does not drop sessions unexpectedly. Done when a session started on one node is accepted on the other and the load balancer behaviour matches the documented design.

  6. Verify sessions survive a node restart

    Restart one web node during a test session, then confirm users who were active on it remain signed in when the request reaches another node. Restart Redis in a controlled window, if your deployment supports it, and check whether sessions persist or users must sign in again, which should match what your business owners accepted. Done when the restart test results are written down and any sign-in loss is explained and accepted or fixed.

  7. Confirm lock warnings are logged as expected

    Review the Moodle logs and web server logs during a multi-tab test to confirm session lock warnings appear only where you expect, such as long-running requests, and that read-only session handling is applied to pages that do not write session data. Ask your Moodle developer or administrator to check any page that still holds the lock for a long time before rolling the configuration to production. Done when the logs show the expected warning pattern, the team has signed off on the results, and the production change ticket references the tested configuration.

Securing a Moodle Redis session handler in production

A Redis session store holds the login state for every active learner and instructor, so it carries the same weight as the database. The cards below cover where that store is exposed, how its data is protected, where credentials live, how eviction can log people out mid-quiz and how the store is watched. Each item needs a check in your own environment, and the Redis side must be confirmed against the hardening guidance published for your Redis version.

Redis reachable from outside the web tier

Session data is only as private as the network path to Redis. Bind the Redis listener to a private interface, restrict access with firewall rules or security groups to the Moodle web and cron nodes, and keep it off any public or shared subnet. Confirm that the Redis version you run supports the access controls you plan to use, and test from a host outside the allowed set that the connection is refused. A reachable Redis instance with no authentication lets anyone on the network read or replace session records.

Session data in transit and at rest

Session records travel between Moodle and Redis on every request, so the connection itself needs protection when it crosses a network segment you do not fully control. Plan TLS for the Moodle-to-Redis connection where your topology requires it and confirm the TLS options that the session_redis settings expose in your Moodle version. For data at rest, confirm with your Redis platform whether disk persistence is enabled and whether the snapshot or append-only files are encrypted, because session contents can be recovered from them.

Redis credentials in the config file

Redis authentication details are stored in the Moodle configuration file, config.php, as session_redis settings. Treat that file as a secret: restrict read access to the web server user and the administrators who deploy it, keep it out of version control and out of web-accessible paths, and avoid copying it into tickets or backups that are widely shared. Rotate the Redis password when staff with access change, and record who can read the file.

Eviction that drops active sessions

If Redis reaches its memory limit and an eviction policy removes keys, active sessions can disappear and users are logged out in the middle of a quiz or submission. Set a memory limit with headroom for peak concurrency, choose an eviction policy that does not remove session keys during load, and confirm the exact policy names in your Redis version's documentation. Test the behavior by filling memory in a staging environment and checking what Moodle reports to the user.

Monitoring and logging the session store

Watch the session store as a production service with its own alerts. Track memory use, connected clients, rejected connections, authentication failures and evictions, and forward Redis logs to the same central system that collects Moodle logs. Review the session lock warnings Moodle writes when requests wait too long, since they can point to a store that is slow or overloaded. Agree who receives each alert and what the response runbook says before go-live.

What a Moodle Redis session handler setup costs and what it needs from your team

What drives the cost of a Moodle Redis session handler setup?

The main drivers are the topology you choose, the number of Redis and web nodes involved, whether TLS and secret handling are in scope, how much testing the change needs, and whether the Redis service is managed or run by your own team. A single Redis host with no encryption in transit is a much smaller job than a multi-host setup with TLS, certificate rotation and a load test under realistic concurrency. Ask any quote to break out design, configuration, testing and handover as separate lines, so you can see which parts scale with your environment and which are fixed.

How long does a Redis session handler setup take?

Duration follows scope. A configuration change on one Moodle site with an existing, well-understood Redis service is short, while a cluster with several web nodes, several Redis hosts, TLS and a verified rollback plan takes longer because each node and each secret needs checking. Testing time often decides the schedule, since lock behavior only shows under concurrent requests. Ask for the timeline in writing against the agreed scope, and confirm which environments (development, staging, production) it covers and who signs off each step.

What does our team need to provide for the work?

Plan to provide access to the Moodle web nodes, the Redis cluster or service and the configuration management path used to deploy config.php changes. You will also need to decide how Redis credentials are issued and stored, which secret store holds them and who can rotate them. A test population of accounts that reflects real course activity makes lock and timeout testing meaningful. Finally, reserve a maintenance window for the cutover and a second window if a rollback is needed.

Can our in-house team set up Redis sessions for Moodle alone?

A capable team with Linux, Redis and Moodle administration experience can do the work alone, especially on a single site with a small topology. The harder parts are verifying session lock behavior, checking that read-only sessions are used only on pages that do not write session data, and proving the setup holds under load. If nobody on the team has run Moodle at concurrency levels similar to your peak, an outside review of the test plan and results is often cheaper than discovering lock problems in production. Be honest about that gap when you decide.

What is the risk if sessions are configured incorrectly?

Misconfigured sessions show up as users being logged out, requests waiting on locks, or pages that hang during busy periods. Errors in TLS settings can block every login, and a missing Redis credential can take the whole site offline. Because these faults often appear only under load, a test run on a quiet staging site can pass while production fails. Plan a rollback path that restores the previous session handler quickly, and confirm in your change record who can trigger it.

What changes at the next Moodle upgrade?

Each Moodle upgrade can change PHP, database and server requirements, so the Redis setup needs a check against the release notes for the target version before the upgrade starts. Moodle 5.1 requires 64-bit PHP 8.2 or later and asks that the web server document root point to the new /public directory, which affects where configuration and session-related paths are read from. Moodle 5.3 requires PHP 8.3 or later and PostgreSQL 17 or other listed database versions. Retest session behavior after each upgrade, because the PHP and Redis client versions in use may also change.

Should we treat Redis session setup as a one-time job or an ongoing cost?

The initial build and testing are one-time costs, while monitoring, Redis patching, credential rotation, certificate renewal and retesting after upgrades recur. Ask whether the quote includes handover documentation and a runbook, since those reduce the recurring effort your team carries. Ongoing support and upgrade testing can be arranged as a retainer, so you can compare that against keeping the work fully in house.

What to confirm about your Moodle release and Redis before you commit

A Redis session handler change touches the Moodle release, the database and PHP stack, the Redis service and the cluster design at once. The cards below list the points to confirm with the Moodle release notes and your Redis provider before you commit to a design.

Moodle release and support window

Confirm which Moodle release you run and how long it receives support. Moodle 4.5 is an LTS release with security support until 4 October 2027, and Moodle 5.1 has security support until 19 April 2027. If your release support ends within your planning horizon, the session work may coincide with an upgrade, so decide the order before you start. Check the current support dates in the Moodle releases page.

4.5 LTS security end
4 Oct 2027
Moodle releases

PHP and database versions

Compare your PHP and database versions with the release notes for your target Moodle version. Moodle 5.1 requires 64-bit PHP 8.2 or later and PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or SQL Server 2017 or later. The Redis PHP extension or client library must also match the PHP version on every web node. Confirm these against the release notes rather than assuming your current stack carries over.

Moodle 5.1 release notes

Redis authentication and TLS mode

Confirm with your Redis provider whether the service supports the authentication method and TLS mode your Moodle nodes need. Ask which certificate authority signs the endpoint, whether client certificates are required, and whether the PHP client on your nodes can verify the chain. A mismatch here usually shows up as failed session writes, so test the connection from every web node before cutover.

Session survival during failover

Decide whether sessions must survive a Redis failover. Ask your provider how failover works, whether it is automatic, and how long clients can be disconnected during it. If users must stay signed in through a failover, confirm the replication and persistence behavior of the service. If a forced sign-in after failover is acceptable, record that as a deliberate decision with the operations team.

Lock factory and session lock behavior

Confirm that the lock factory for cron and tasks was chosen in the same cluster design as the session handler. Redis sessions change how session locks behave, so the lock timeout and warning settings should be reviewed alongside the lock factory choice. Verify that the shared directories used by the cluster are also reviewed, because the session, cache and data paths interact with the same web nodes.

How DeployOpen scopes and delivers Moodle session changes

DeployOpen plans the move of Moodle sessions to Redis as a written, fixed-scope change inside your own infrastructure. The work covers the session_redis settings, the lock and serializer choices, testing under realistic traffic, and a handover your operations team can run without us.

How we scope

  • Inventory which Moodle pages hold session locks today and which requests could run read-only.
  • Agree in writing the Redis topology, TLS requirements, host list and failover behavior the session handler must support.
  • Confirm the Moodle version, PHP build and web node count, since these shape the settings and the test plan.

How we build

  • Configure the session_redis settings in a staging copy of your Moodle, including multiple hosts and TLS where your Redis requires it.
  • Set lock timeouts, lock warnings, serializer and compression options, and read-only session handling against measured page behavior.
  • Run load tests on staging that mirror your login, quiz and course traffic, then record the session lock warnings and timings observed.

How we hand over

  • Deliver the final configuration, Redis key and eviction settings, and a change record that names each setting and why it was chosen.
  • Document the rollback steps, the monitoring signals to watch for session lock warnings, and the Redis failover behavior your team must test.
  • Walk your platform and Moodle administrators through the runbook and confirm they can apply the same settings to a new node.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer, covering changes after a Moodle upgrade or a Redis change.
  • Retest session behavior when you add web nodes, change Redis topology or move to a newer Moodle release.
  • Ask any provider, including us, to confirm in writing how the session settings will be verified before go-live.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.