Home > Backend Development > PHP Problem > How to install and configure redis in php

How to install and configure redis in php

coldplay.xixi
Release: 2023-03-04 08:32:01
Original
3124 people have browsed it

How to install and configure redis in php: first download and install redis, and use the phpinfo function to check the version information of PHP; then copy [.dll and .pdb] to the ext directory of php; then modify [php. ini], and restart Apache; finally open the redis service for testing.

How to install and configure redis in php

How to install and configure redis in php:

1. Download and install redis

1. First go to the github website to download

2. According to the actual situation, cp the 64bit content to a custom drive letter directory, such as D:\Redis;

3 .Open cmd, cd /d, switch to the Redis-server.exe directory, run redis-server.exe redis.conf;

4. At this time, open another cmd window. Do not close the original one, otherwise it will not work. Access the server.

Switch to the redis directory and run redis-cli.exe -h 127.0.0.1 -p 6379 (-a password remote);

5. Set the key-value pair set myKey abc

Get the key-value pair get myKey;

At this time, in the windows environment, both the redis server and the client run successfully.

2. PHP installation redis extension

1. Use the phpinfo() function to view the PHP version information, which will determine the extension file version.

2. Download php_igbinary-1.2.1-5.5-ts-vc11-x64.zip, php_redis-2.2.5-5.6-ts-vc11-x64.zip (be sure to ensure the correctness of the version)

3. After decompressing, copy php_redis.dll and php_redis.pdb to the ext directory of php

4. Modify php.ini , (PS: This php.ini file is in the Apache directory) Add to the file:

; php_redis
extension=php_igbinary.dll
extension=php_redis.dll
Copy after login

Note: extension=php_igbinary.dll must be placed in extension=php_redis .dll, otherwise this extension will not take effect

5. After restarting Apache, use phpinfo to check whether the extension is successfully installed

6. After opening the redis service, you can use the following test Whether it can be called.

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect(&#39;127.0.0.1&#39;, 6379);
echo "Connection to server sucessfully";
//设置 redis 字符串数据
$redis->set("tutorial-name", "Redis tutorial");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>
Copy after login

Related learning recommendations: php programming (video)

The above is the detailed content of How to install and configure redis in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template