Principle: PHP Default extension library does not contain Redis extensions; To support Redis extensions, you need to have redis.so this extension file
So our goal is to generate the redis.so extension file and modify the php.ini to support the Redis extension.
Prepare the test environment and software:
VM Virtual machine;
CentOS5.5 (has set up a good LNMP environment);
Redis-2.6.14 (Installation method, see my previous blog post);
phpredis.tar.gz (no online download);
My host computer is win10.
1. Upload the phpredis.tar.gz to Linux and unzip the
2. Enter Phpredis source Directory command: # CD Phpredis
(Here we need to know the PHP installation directory, I am here:/usr/local/php/bin)
3. Execute the command in the Phpredis source directory:/usr/local/php/bin/phpize:
Description: This phpize file in the/php/bin directory is the interface that PHP reserved when we need to install third-party extension libraries in the future
4. Perform the compilation
#./configure--with-php-config=/usr/local/php/bin/php-config
5. Installation
Make && make install
6. After the installation is complete, the last few pieces of code will tell us where the redis.so extension file is stored:
Put in:/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/this directory
This directory is a bit deep, it's okay, let's go to this directory and see what's Inside:
7. Enter the/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/directory to view
There's just one redis.so file in it, and that's the redis.so file we're going to generate. The next step is to modify php.ini.
8. Configure php.ini; let PHP support Redis extensions
Open php.ini to add this code anywhere inside:
extension= "Redis.so"
Save exit, restart PHP
Related commands:
Close Php:killall php-fpm
Start PHP:/USR/LOCAL/PHP/SBIN/PHP-FPM
Restart Nginx:service nginx Restart
9. Visit phpinfo.php and see that you have a redis extension
10. Next Test our PHP to see if we can properly operate Redis
Create phpredis.php under the Nginx Web root HTML to test the PHP connection to Redis;
# VI phpredis.php
Save exit to access this file with your browser:
Connection Successful!! Done
Redis can now be operated with PHP!
Share a Phpredis's Chinese handbook here: http://www.cnblogs.com/ikodota/archive/2012/03/05/php_redis_cn.html
The methods for working with Redis in PHP are all inside.
Installing Redis in a Linux environment