Home  >  Article  >  Backend Development  >  Installing redis and phpredis in centos6.4

Installing redis and phpredis in centos6.4

WBOY
WBOYOriginal
2016-07-25 08:57:391045browse
  1. $ wget http://download.redis.io/releases/redis-2.6.16.tar.gz
  2. $ tar xzf redis-2.6.16.tar.gz
  3. $ cd redis-2.6.16
  4. $ make install
Copy code

2. Configuration

  1. $ mkdir /etc/redis
  2. $ cp redis.conf /etc/redis/redis.conf
  3. $ gedit /etc/sysctl.conf$ sysctl -p
Copy code

Note: Add vm.overcommit_memory=1

to the end of the sysctl.conf file

3. Start testing

  1. $ /usr/local/bin/redis-server /etc/redis/redis.conf
  2. $ /usr/local/bin/redis-cli
  3. $ set test xjx
  4. $ get test
Copy the code

4. Turn on the computer

  1. $ gedit /etc/redis/redis.conf

  2. Set daemonize yes

  3. $ gedit /var/run/redis.pid

  4. Save directly, mainly Create this file

  5. gedit /etc/init.d/redis

  6. Edit the script, you can also download it yourself or enter the following content
  7. #!/bin/bash
  8. #
  9. # redis - this script starts and stops the redis-server daemon
  10. #
  11. # chkconfig: - 80 12
  12. # description: Redis is a persistent key-value database
  13. # processname: redis-server
  14. # config: /etc/redis/redis.conf
  15. # pidfile : /var/run/redis.pid

  16. source /etc/init.d/functions

  17. BIN="/usr/local/bin"

  18. CONFIG=" /etc/redis/redis.conf"
  19. PIDFILE="/var/run/redis.pid"

  20. ### Read configuration

  21. [ -r "$SYSCONFIG" ] && source "$ SYSCONFIG"

  22. RETVAL=0

  23. prog="redis-server"
  24. desc="Redis Server"

  25. start() {

  26. if [ -e $PIDFILE ];then

  27. echo "$desc already running...."
  28. exit 1
  29. fi

  30. echo -n $"Starting $desc: "

  31. daemon $BIN/$prog $CONFIG

  32. RETVAL=$?

  33. echo
  34. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
  35. return $RETVAL
  36. }< /p>
  37. stop() {

  38. echo -n $"Stop $desc: "
  39. killproc $prog
  40. RETVAL=$?
  41. echo
  42. [ $RETVAL -eq 0 ] && rm -f /var/lock /subsys/$prog $PIDFILE
  43. return $RETVAL
  44. }

  45. restart() {

  46. stop
  47. start
  48. }

  49. case "$1" in

  50. start )
  51. start
  52. ;;
  53. stop)
  54. stop
  55. ;;
  56. restart)
  57. restart
  58. ;;
  59. condrestart)
  60. [ -e /var/lock/subsys/$prog ] && restart
  61. RETVAL=$?
  62. ;;
  63. status)
  64. status $prog
  65. RETVAL=$?
  66. ;;
  67. *)
  68. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  69. RETVAL=1
  70. esac

Copy code

Change file permissions:

  1. $ chmod 755 /etc/init.d/redis
Copy code

Add startup:

  1. $ chkconfig --add redis
  2. $ chkconfig --level 345 redis on
  3. $ chkconfig --list redis
Copy the code

and then restart the server, $ service redis status to check whether it is configured correctly

Next, we will introduce the installation and configuration methods of phpredis.

2. phpredis

1. Download and decompress by yourself https://github.com/nicolasff/phpredis/archive/master.zip

2. Installation

  1. $ cd /root/phpredis-master
  2. $ /usr/local/php/bin/phpize
  3. $ ./configure --with-php-config=/usr/local/php/bin/php- config
  4. $ make && make install
Copy code

Note: The path is modified according to the actual situation 3.php extension $ gedit /usr/local/php/etc/php.ini Add extension=redis.so, and then restart php-fpm (non-nginx)

4.Test

  1. $redis = new Redis();
  2. $redis->connect('127.0.0.1',6379);
  3. $redis->set('test','hello world!');
  4. echo $redis->get('test');
Copy code

3. phpredisadmin http://down.admin5.com/php/75024.html Just download and unzip it to the www directory. It is provided here for everyone. It is best not to use the latest official version. You will understand the reason after using it.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn