1. Install redis
cd /usr/local/src
tar zxvf redis-2.8.20.tar.gz
# Copy to the /usr/local/redis folder
cp -r redis-2.8.20 /usr /local/redis
cd /usr/local/redis
make && make install
2. Start redis
cd /usr/local/redis/src
./redis-server
3. PHP install redis extension
cd /usr/local/src
tar zxvf phpredis-2.2.4.tar.gz
cd phpredis-2.2.4
/usr/local/php/bin/phpize
./configure --with-php-c/local /php/bin/php-config
make
make install
Record the path where the extension file is located, mine is:
/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
4. Enable redis extension
vim /usr/local/php/etc/php.ini
Add the following content at the end of php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-non -zts-20121212/redis.so
After restarting the server, you can see the relevant information of the redis extension in phpinfo() and the installation is successful
5. Test
vim redis.php
<?php $config = array(
'host' => '127.0.0.1',
'port' => 6379,
);
$handle = new Redis( );
$handle->connect( $config['host'], $config['port'] );
$redis = $handle;
$testKey = 'testKey';
$testVal = 'This is a Test Value';
var_dump($redis->set($testKey, $testVal));
echo '<br>';
var_dump($redis->get($testKey));
Copy after login
Result:
The above introduces the redis installation and the redis extension of PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.