How to Fix the "Class 'Redis' Not Found" Error on Windows for Laravel
If you’re developing a Laravel application on Windows and encounter the error Class "Redis" not found
, it means that Laravel is trying to use the Redis PHP extension, but it’s not installed or enabled on your system. Here’s a step-by-step guide to resolving this issue on a Windows environment.
Step 1: Download and Install the Redis PHP Extension
Download the Redis Extension DLL:
- Visit the PECL Redis page to find the version of Redis that matches your PHP version.
- Download the appropriate
php_redis.dll
file for your PHP version from the PECL website.
Place the DLL File:
- Move the downloaded
php_redis.dll
file to your PHP extension directory. This is typically located atC:\php\ext
on Windows.
- Move the downloaded
Step 2: Enable the Extension in php.ini
Open the
php.ini
File:- Navigate to your PHP installation directory, usually
C:\php
, and open thephp.ini
file with a text editor.
- Navigate to your PHP installation directory, usually
Add the Redis Extension:
- Add the following line to enable the Redis extension:ini
extension=redis
- Save and close the
php.ini
file.
- Add the following line to enable the Redis extension:
Step 3: Restart Your Web Server
For Apache Users:
- Open Command Prompt or PowerShell and restart Apache with the following command:bash
httpd -k restart
- Open Command Prompt or PowerShell and restart Apache with the following command:
For Other Web Servers:
- Restart the web server according to its specific method.
Step 4: Verify the Installation
Using PHP CLI:
- Open Command Prompt and run:bash
php -m | findstr redis
- If
redis
appears in the output, the extension has been successfully installed.
- Open Command Prompt and run:
Using Laravel:
- Check your Laravel application to ensure that Redis is now recognized and functioning properly.
Troubleshooting Tips
- Ensure Compatibility: Double-check that the
php_redis.dll
file you downloaded matches your PHP version and architecture (x86 or x64). - Check PHP Configuration: Ensure that the
php.ini
file you edited is the one being used by your PHP installation.
By following these steps, you should be able to resolve the Class "Redis" not found
error and get Redis up and running with your Laravel application on Windows.
No comments: