: This article describes how to enable PHP to support Redis. if you are interested in the PHP Tutorial, refer to it. Principle: php default extension library does not include redis extension; to support redis extension, you need the extension file redis. so.
So our goal is to generate the redis. so extension file and modify php. ini to support redis extension.
Prepare the test environment and software:
Vmvirtual machine;
CentOS5.5 (LNMP environment has been set up );
Redis-2.6.14 (installation method, see my previous blog );
Phpredis.tar.gz (download from the Internet without it );
My host computer is Win10.
1. Upload phpredis.tar.gz to Linux and decompress it.
2. enter the phpredis Source Code Directory command: # cd phpredis
(Here we need to know the php installation directory. here I am:/usr/local/php/bin)
3. execute the command in the phpredis Source Code Directory:/usr/local/php/bin/phpize, for example:
Note: The phpize file in the/php/bin directory is reserved by php for third-party extension libraries.
4. execute compilation
#./Configure -- with-php-c/local/php/bin/php-config
5. install
Make & make install
6. after the installation is complete, the last code segment will tell us the storage location of the redis. so extension file:
Put it in the directory:/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
This directory is a bit deep. it doesn't matter. let's go to this directory and see what's in it:
7. go to the/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/directory to view
There is a redis. so file, which is the redis. so file we want to generate. The next step is to modify php. ini.
8. configure php. ini to allow php to support redis extension
Open php. ini and add this code anywhere in it:
Extension = "redis. so"
Save and exit. restart php.
Related commands:
Disable php: killall php-fpm
Start php:/usr/local/php/sbin/php-fpm
Restart Nginx: service nginx restart
9. access phpinfo. php and check that the redis extension is available.
10. Next, let's test whether our php can operate redis correctly.
Create phpredis. php under the nginx website root directory html to test php connection to redis;
# Vi phpredis. php
Save and exit. use your browser to access this file:
Connection successful !! Success
Now you can use php to operate redis!
Here is a phpredis Chinese Manual: http://www.cnblogs.com/ikodota/archive/2012/03/05/php_redis_cn.html
The php methods for operating redis are all in it.
Come here first. if you like this blog, please comment!
The above section describes how to enable PHP to support Redis, including related content, and hope to help those who are interested in PHP tutorials.