Home Backend Development PHP Tutorial Installing redis and phpredis in centos6.4

Installing redis and phpredis in centos6.4

Jul 25, 2016 am 08:57 AM

  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. <p>$ gedit /etc/redis/redis.conf
  2. Set daemonize yes</p>
  3. <p>$ gedit /var/run/redis.pid
  4. Save directly, mainly Create this file</p>
  5. <p>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</p>
  16. <p>source /etc/init.d/functions</p>
  17. <p>BIN="/usr/local/bin"
  18. CONFIG=" /etc/redis/redis.conf"
  19. PIDFILE="/var/run/redis.pid"</p>
  20. <p>### Read configuration
  21. [ -r "$SYSCONFIG" ] && source "$ SYSCONFIG"</p>
  22. <p>RETVAL=0
  23. prog="redis-server"
  24. desc="Redis Server"</p>
  25. <p>start() {</p>
  26. <p> if [ -e $PIDFILE ];then
  27. echo "$desc already running...."
  28. exit 1
  29. fi</p>
  30. <p> echo -n $"Starting $desc: "
  31. daemon $BIN/$prog $CONFIG</p>
  32. <p> RETVAL=$?
  33. echo
  34. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
  35. return $RETVAL
  36. }< /p>
  37. <p>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. }</p>
  45. <p>restart() {
  46. stop
  47. start
  48. }</p>
  49. <p>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</p>
  71. <p&gt ;exit $RETVAL</p>
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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles