Install redis and phpRedis extension in linux-php Tutorial

Source: Internet
Author: User
Install redis and phpRedis extensions in linux
    1. Install redis and php Redis extension in linux

    2. Environment configuration: centos6.0 nginx/1.0.0 php/5.3.8 mysql/5.5.17

    3. Step 1. download redis

    4. You can download the latest version at http://redis.io/

    5. I use redis 2.8.11.

    6. Go to the software installation package storage directory: cd/var/install/software/

    7. Wget http://download.redis.io/redis-stable.tar.gz

  1. Step 2. compile the source program

  2. Tar xvzf redis-stable.tar.gz

  3. Cd redis-stable

  4. Make

  5. Make install

  6. If an exception occurs in make:

  7. 1) make [2]: cc: Command not found

  8. Cause of exception: gcc is not installed

  9. Solution: yum install gcc-c ++

  10. 2) zmalloc. h: 51: 31: error: jemalloc/jemalloc. h: No such file or directory

  11. Cause of exception: Some compilation dependencies or issues left behind by the original compilation

  12. Solution: make distclean. Clean up and then make.

  13. After make is successful, make test has an exception in make test.

  14. 1) couldn't execute "tclsh8.5": no such file or directory

  15. Cause of exception: tcl is not installed

  16. Solution: yum install-y tcl.

  17. After the make command is executed, five executable files are generated in the src directory, they are redis-server, redis-cli, redis-benchmark, redis-check-aof, and redis-check-dump. Their functions are as follows:

  18. Redis-server: daemon startup program of the Redis server

  19. Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate based on its plain text protocol.

  20. Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration

  21. Redis-check-aof: update log check

  22. Redis-check-dump: used for local database check

  23. Step 3. configure

  24. Cp redis-server/usr/local/bin/

  25. Cp redis-cli/usr/local/bin/

  26. Create a directory to store the configuration file.

  27. Mkdir/etc/redis

  28. Mkdir/var/redis

  29. Mkdir/var/redis/log

  30. Mkdir/var/redis/run

  31. Mkdir/var/apsaradb for redis/6379

  32. Find the configuration file template in the redis root directory and copy it to the following location.

  33. Cp redis. conf/etc/redis/6379. conf is modified using the vim command

  34. Daemonize yes

  35. Pidfile/var/redis/run/redis_62.16.pid

  36. Logfile/var/redis/log/redis_62.16.log

  37. Dir/var/redis/6379

  38. Finally run redis:

  39. $ Redis-server/etc/redis/6379. conf

  40. Use netstat-atln to check whether the port is successfully installed.

  41. Step 4: operate the Redis database

  42. #./Redis-cli

  43. "Http://img.blog.csdn.net/20140617150954812? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt ="/>

  44. Next we will perform a simple operation on the database. When the instance is enabled:

  45. 1. Insert data

  46. Redis 127.0.0.1: 6379> set name wwl

  47. OK

  48. Set a key-value pair.

  49. 2. query data

  50. Redis 127.0.0.1: 6379> get name

  51. "Wwl"

  52. Obtain the value corresponding to the key.

  53. 3. delete a key value

  54. Redis 127.0.0.1: 6379> del name

  55. Delete the key and the corresponding value.

  56. 4. check whether the verification key exists

  57. Redis 127.0.0.1: 6379> exists name

  58. (Integer) 0

  59. 0 indicates that the key does not exist; 1 indicates that the key exists.

  60. Step 5. download phpredis extension

  61. Download the https://github.com/nicolasff/phpredis/downloads first

  62. # Wget https://github.com/nicolasff/phpredis/downloads

  63. # Tar-zxvf nicolasff-phpredis-2.1.3-124-gd4ad907.tar.gz

  64. # Mv nicolasff-phpredis-d4ad907 php-5.3.8/ext/phpredis/

  65. # Cd php-5.3.8/ext/phpredis/

  66. #/Usr/local/php/bin/phpize

  67. #./Configure -- with-php-config =/usr/local/php/bin/php-config

  68. # Make & make install

  69. Configure php. ini

  70. Vi/usr/local/php/lib/php. ini

  71. (Add:

  72. Extension = redis. so

  73. )

  74. First, check whether there is extension_dir = /.......

  75. Restart apache or nginx (reload php --->/etc/init. d/php-fpm restart)

  76. By now, you can use phpinfo to view the redis extension.

  77. If phpinfo does not have redis extension information, add/etc/php. d/redis. ini (the path is my local)

  78. The content of redis. ini is as follows:

  79. ; Enable mysql extension module

  80. Extension = redis. so

  81. Restart apache or nginx (reload php --->/etc/init. d/php-fpm restart)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.