This article is intended to those who wish to install Redis and PHP extension for interfacing with Redis on their XAMPP installation on windows. As I had required once to setup a Redis Server on my local development machine and utilize it as it was not possible to test on a production environment.
Redis is more than just a in-memory caching system and is popular choice among developers because of persistence storage and versatile features provided by it. Redis runs as a separate service and is called by any other process including PHP. You can simply think it as relation like PHP – MySQL relation. To handle communication between Redis service and the process, Redis clients are introduced. predis
and phpredis
are two very popular and regularly maintained Redis clients for PHP, former is a PEAR package and latter is a PECL extension.
PHP Extension Community Library or PECL, are simply packages written in C and further compiled into a .dll for windows. These .dll files are kept into php/ext
directory and we need to add an entry into php.ini
in order to use the particular package.
PEAR on another hand, is PHP Extension and Application Repository, consisting a number of php files, available to be used by the end user just like other normal php file which are integrated into your project through autolaoding or included by you manually. In trend with time, installing these package using Packagist with Composer is preferred which also facilitate dependency management and PEAR is less favorable.
There is too less support present for Redis in windows operating system as compared to linux operating system. It is always wise to install Redis Server locally first, then install Redis client and setup your script to communicate with this server to test basic functionalities in your system. Without a clear documentation and support, it’s very difficult to make Redis server up and working with it in windows machine. So here in this article, you will find how easy is to setup and use Redis with PHP on a windows system.
Install Redis & Redis extension in PHP on XAMPP on windows
First of all we will install Redis then PECL extension for PHP step by step.
Step 1:
Download and install Redis service using either of the given options. Regardless of download and installation method you select, you must have to ensure that the Redis service is running on the system after installation:
(i) Redis for windows(x64) – https://github.com/MSOpenTech/redis/releases
(ii) Redis for windows(x86) – http://ruilopes.com/redis-setup/
(iii) Linux version of Redis on windows using Vagrant – https://github.com/ServiceStack/redis-windows
I am using the second option. It also needs a machine restart after installation to let Redis server run. Install Redis service as a windows service which is asked during installation process to automatically start Redis on system boot each time.
If your Redis service is installed and running you can test it by running Redis Client tool in your installation folder which is basically a command line tool. On the command line you will see something like this:
On the command prompt type ping
and press enter, then you will see PONG
as result if your Redis server is running.
Step 2:
This step involves to download and setup an extension in PHP to communicate with Redis Server. I’m using PECL extension. You can also use PEAR extension (using composer) if you prefer as I have already mentioned difference between them.
Download PECL extension (DLL file) from https://pecl.php.net/package/redis/2.2.7/windows
But before this you need to know which PHP version have you installed and whether thread safety is enabled or not. To know that, use phpinfo()
function in a PHP file and access the file on browser using localhost. You will see PHP installation information where you can check for version and thread safety.
For thread safety enabled system, download ts
version of dll
according to your PHP version and system architecture (x86/x64) otherwise use nts
version. Extract the contents and copy the .dll
file in xampp/php/ext
directory.
Next, browse the xampp/php
folder, edit php.ini
file located there and add string extension="php_redis.dll"
along with other extensions and restart your apache server.
Now it’s time to check. Write the code below in a php file, save it and access in browser. If everything is done as described, you will see dolly
as output:
1 2 3 4 5 6 | $redis = new Redis(); $redis->connect('127.0.0.1'); $redis->set('hello', 'dolly'); $value = $redis->get('hello'); echo $value; |
So give it a try and let me know your experience about installing Redis & Redis extension in PHP on XAMPP on windows.
thankyou i use yii2 and php 8.1 its worked
Thank you.
i have a php 7.2.7 version what should i choose for pecl ?
@hamzaaitsidisaid:disqus
You should choose PECL package 4.2 for Redis. Check the link below and you can find TS as well as NTS DLL at the bottom:
https://pecl.php.net/package/redis/4.2.0/windows
Hey
https://google.com/#btnI=rutigunu&q=ichatster.com&ab=psquublwbe
My id 482605
Getting Error: Fatal error: Class ‘Redis’ not found in C:xampphtdocspredisindex.php on line 3
@disqus_Y4WiENu620:disqus first ensure that you have enabled Redis extension by echoing phpinfo() function (You will see redis section in browser page). Also you would need to restart apache. This comment below http://fellowtuts.com/php/install-redis-redis-extension-in-php-on-windows/#comment-2841998586 is also helpful to you
Not working for me ..did everything as mentioned.
A doubt, there are many files in the zip so all of them needs to be copied or just the dll one?
@disqus_bTjkvTf0Uw:disqus just try to install only Redis first .
Check if Redis service installed & listed in Control Panel > Administrative Tools > Services
In windows you need to copy dll one only.
Also check for @arungisyadi:disqus ‘s comment, I have not tested it.
Its fabulous post,really very useful for beginners.
Perfect
thanks
One thing need to take note here… If using XAMPP, despite that you’re using X64 processor. The PECL library still need to use X86. This is because XAMPP doesn’t have environment for x64.
Just hope this helps anyone having trouble installing redis for PHP.
Hi @arungisyadi:disqus
Thank you for this useful information
Excellent post and really helped me out with a localhost REDIS issue!
Cheers,
Joseph Gourvenec
https://etailthis.com