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.
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.
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.
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
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:
$redis = new Redis();
$value = $redis->get('hello');
So give it a try and let me know your experience about installing Redis & Redis extension in PHP on XAMPP on windows.