This article mainly introduces the Php-redis installation test notes, this article explains Redis installation, Redis test, installation Phpredis extension, test Php-redis and so on, the need for friends can refer to the following
-->
Back-end development uses PHP operation Redis, where the problems encountered during the installation test are summarized and recorded for future reference! (System for Ubuntu)
1.redis Installation
Download Address: http://download.redis.io/releases/
Decompression Installation:
The code is as follows:
TAR-XVF redis-2.8.17.tar.gz
Make
sudo make install
For ease of use, create the Redis directory under the/usr directory and copy the following files to the/usr/redis/directory:
The code is as follows:
/yourdir/redis-2.8.17/redis.conf
/yourdir/redis-2.8.17/src/redis-benchmark
/yourdir/redis-2.8.17/src/redis-server
/yourdir/redis-2.8.17/src/redis-cli
Of course, you can also use the soft connection to achieve the purpose of convenience. In addition, you can also add redis-server to boot up, here Conlio.
2.redis Test
1 first open the Redis service-side program
To facilitate testing, we will redis.conf the loglevel and logfile values in the configuration file, as follows:
LogLevel Debug
LogFile "/tmp/redis.log"
jay13@ubuntu:/usr/redis$ Redis-server redis.conf
2) Open the Redi client, through the client to the Redis database for the increase and deletion of the search operation. The logs generated during the entire operation can be viewed in/tmp/redis.log.
Take the simplest key operation, for example, with the following example:
The code is as follows:
jay13@ubuntu:/usr/redis$ REDIS-CLI
127.0.0.1:6379> Set JAY13 jb51.net
Ok
127.0.0.1:6379> set Jay Hello,world
Ok
127.0.0.1:6379> get Jay
"Hello,world"
127.0.0.1:6379> Get JAY13
"Jb51.net"
127.0.0.1:6379> del Jay
(integer) 1
127.0.0.1:6379> get Jay
(nil)
127.0.0.1:6379> Set JAY13 www.jb51.net
Ok
127.0.0.1:6379> Get JAY13
"Www.jb51.net"
3. Install Phpredis Extension
When installing PHP with sudo apt-get install PHP5, Phpize is not installed by default and Phpredis is required when we install phpize, so we need to install Phpize first.
1 we get phpize by installing PHP developer tools. Execute the following command:
The code is as follows:
sudo apt-get install Php5-dev
2) Get Phpredis source files
Latest Phpredis Address: Https://github.com/nicolasff/phpredis
Follow the instructions on GitHub to install the following
The code is as follows:
Phpize
./configure--enable-redis-igbinary
Make && make install
You may receive the following error description:
The code is as follows:
Checking for Igbinary includes ... configure:error:Cannot find Igbinary.h
This is because we do not have igbinary expansion, this is phpredis dependent on a thing.
Okay, how do I install igbinary?
The use of Apt-get does not fail to install, and we install it by downloading the installation files.
The code is as follows:
wget <a href= "http://pecl.php.net/get/igbinary-1.1.1.tgz" >http://pecl.php.net/get/igbinary-1.1.1.tgz</a >
TAR-XZVF igbinary-1.1.1.tgz
CD igbinary-1.1.1
Phpize
./configure # No need for extra config params
Make
Make install
After installing the Igbinary, you can install Phpredis with the following command.
The code is as follows:
Phpize
./configure–enable-redis-igbinary
Make && make install
At this point, the installation is complete.
We modified the php.ini configuration file to add the two extensions we just installed to the php.ini file and added the following statement:
The code is as follows:
Extension=igbinary.so
Extension=redis.so
Restart apache,done!!!
4. Test Php-redis
In the Web page root/var/www/, create a new file test.php, which reads as follows:
The code is as follows:
<?php
$redis = new Redis ();
$redis->connect (' 127.0.0.1 ', 6379);
$redis->set (' Jay13 ', ' www.jb51.net ');
Echo ' JAY13: '. $redis->get (' Jay13 ');
Echo ' </br> ';
Echo ' Jay12: '. $redis->get (' Jay12 ');
?>
The results are shown below: