skip to Main Content

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


  1. Chosen as BEST ANSWER

    For XAMPP servers

    1. Install a thread-safe version of phpredis from here by following the Windows DLL links for your desired version and scrolling down.

    2. Extract the downloaded ZIP and copy the .dll file in it to C:XAMPPphpext.

    3. Restart the Apache server, then from a command-line run php -m and look for redis in the output to confirm that the phpredis extension is being loaded.

    4. 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.

    5. To test that your Redis connection is working, run the following commands from a Cygwin/WSL/CMD terminal:

      $ memurai.exe
      // Start the Memurai Redis server
      $ ping
      // Should output PONG
      $ set test "It's alive"
      // Should output OK
      
    6. Finally, to test whether the data you set above has been persisted, restart your PC and run the following commands:

      $ memurai.exe
      $ get test
      // Should output "It's alive"
      $ del test // Delete the test key to tidy up
      

  2. For Ubuntu and Debian servers

    1. Use your distro’s package manager to install the phpredis extension, replacing 8.1 with the version of PHP that your server is running (run php -v to check):

      apt-get install php_redis8.1
      
    2. Run php -m and look for redis in the list of extensions to confirm that the phpredis extension is being loaded.

    3. 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:

      curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg &&
      echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list &&
      sudo apt update &&
      sudo apt install redis-server
      
    4. Once the Redis server and CLI have been installed, open the Redis config file with

      sudo nano /etc/redis/redis.conf 
      

      …and look for the supervised option – change it from no to systemd:

      # /etc/redis/redis.conf
      supervised systemd
      
    5. Restart the redis service to make this configuration change take effect:

      sudo systemctl restart redis.service
      
    6. To test that Redis is installed and running correctly, run the following commands:

      $ redis-cli
      // Start the Redis CLI
      $ ping
      // Should output PONG
      $ set test "It's alive"
      // Should output OK
      
    7. Finally, to test whether the data you set above has been persisted, run the following commands:

      $ exit
      $ sudo systemctl restart redis
      $ redis-cli 
      $ get test
      // Should output "It's alive"
      $ del test // Delete the test key to tidy up
      

    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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search