Redis is a high-performance open source in-memory database that provides key-value storage, publish/subscribe, scripting and other functions. In PHP development, redis, as an efficient caching system, is widely used in scenarios such as distributed caching and session storage. This article will introduce how to install and configure the php redis extension in a Windows environment.
Under Windows, we need to use the version compiled with the VC compiler. We can download it from the redis official website or from Github. Here we recommend downloading the latest version from Github and selecting the latest stable version for download.
After the download is completed, we will unzip redis to the root directory of drive C, for example, unzip it to the C:\redis directory.
Under Windows, we can use redis-server.exe provided by redis to run as a Windows service. The specific method is as follows:
1) Create a configuration file named redis.windows.conf in the C:\redis directory.
2) Modify the content in the redis.windows.conf file:
port 6379 requirepass your_password
Your_password here is the password you set yourself, and you can set it arbitrarily.
3) In the cmd command line, open it as an administrator, enter the C:\redis directory, and run the following command to install the redis service:
redis-server.exe --service-install redis.windows.conf --service-name Redis --port 6379
After the installation is successful, we can The redis service is seen in the list, and we can see in the service properties that its service name is Redis and the port is 6379.
If you want to uninstall the redis service, you can run the following command:
redis-server.exe --service-uninstall --service-name Redis
Before installing the php redis extension, we need to make sure The PHP environment and PHP development environment have been installed. If it has not been installed yet, you can follow the steps below to install it.
1) Download the latest PHP installation package from the official website and install it.
2) Download the latest PHP DLL development package and extract it to the ext directory under the PHP installation directory.
Download address: http://windows.php.net/downloads/pecl/releases/redis/
3) Add redis extension configuration in php.ini:
extension=php_redis.dll
Make sure that this configuration item is after other extended configuration items.
Note: If we use the php_redis.dll extension in PHP 7.x version, we need to install the MSVC 14 compiler version, otherwise the installation may fail.
After installing the php redis extension, we can use the following code to test whether php redis is installed successfully:
<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->set('foo', 'bar'); echo $redis->get('foo');
Execute the code, If bar is output, it means that redis is installed successfully and you can use it happily!
Summary
This article introduces how to install and configure php redis extension in Windows environment, including downloading redis, installing redis service, installing php redis extension, testing php redis and other steps. I hope this article can help you install and configure the PHP redis extension quickly and smoothly.
The above is the detailed content of How to install and configure php redis extension in Windows environment. For more information, please follow other related articles on the PHP Chinese website!