The Laravel documentation recommends using the phpredis
PHP extension instead of the predis
package due to having better performance, which PHP extensions generally seem to at the cost of a more complicated setup. Unfortunately the documentation is thin on the actual process of installing this extension, or resources to doing so.
Like all PHP extensions phpredis
is not available in Composer – how do I install it on my server?
2
Answers
For XAMPP servers
Install a thread-safe version of
phpredis
from here by following the Windows DLL links for your desired version and scrolling down.Extract the downloaded ZIP and copy the
.dll
file in it toC:XAMPPphpext
.Restart the Apache server, then from a command-line run
php -m
and look forredis
in the output to confirm that thephpredis
extension is being loaded.Bizarrely, Redis has no official Windows release despite being the most widely used OS for development servers by a large margin. This leaves us having to trust one of the many third-party binaries out there. The most reputable of these and the most likely to still be around in the future seems to be Memurai, which is an enterprise product that is free for development use - this is fine for our needs because no-one should be running a production server on XAMPP. Installing the free version of Memurai will automatically add a Windows service to start the Redis server with your PC.
To test that your Redis connection is working, run the following commands from a Cygwin/WSL/CMD terminal:
Finally, to test whether the data you set above has been persisted, restart your PC and run the following commands:
For Ubuntu and Debian servers
Use your distro’s package manager to install the
phpredis
extension, replacing 8.1 with the version of PHP that your server is running (runphp -v
to check):Run
php -m
and look forredis
in the list of extensions to confirm that thephpredis
extension is being loaded.Install the Redis server and CLI by running the following command (copy-paste and enter to run the whole thing at once) and following the instructions:
Once the Redis server and CLI have been installed, open the Redis config file with
…and look for the
supervised
option – change it fromno
tosystemd
:Restart the
redis
service to make this configuration change take effect:To test that Redis is installed and running correctly, run the following commands:
Finally, to test whether the data you set above has been persisted, run the following commands:
You now have Redis server installed on your server and successfully using the
phpredis
extension as recommended by Laravel.See here for more detailed instructions to this process, as well as how to configure a password to Redis for additional security (newer versions of Redis already bind the server to localhost by default, so this usually isn’t necessary to do).