Tag Archives: redis

Installing PHPRedis

6 Aug

Compile and Build PHPRedis

  1. mkdir -p /opt/redis/php
  2. cd /opt/redis/php
  3. wget –no-check-certificate https://github.com/nicolasff/phpredis/zipball/master
  4. unzip nicolasff-phpredis-2.1.2-4-g765b9a7.zip
  5. cd nicolasff*/
  6. Ensure the phpize command from /usr/bin is executed.
    1. PATH=/usr/bin:$PATH; export PATH
  7. make clean (If this is your first time building PHPRedis, this command will fail and that is ok)
  8. phpize
  9. ./configure
  10. make
  11. make install
    • This Will copy redis.so to /usr/lib64/php/modules on 64 bit OS (production systems)
    • Will copy redis.so /usr/lib/php/modules on 32 bit OS (Dev systems)
  12. Specify redis.so as a PHP extension
    1. echo “extension=redis.so” > /etc/php.d/phpredis.ini
  13. Restart Apache
    1. service httpd restart

Reference

  1. The API is available here https://github.com/nicolasff/phpredis#readme.

Redis on Centos

2 Jul

Setup Latest Redis

  • Download and build latest redis
    1. cd /opt/redis
    2. Dowload the latest stable version from http://redis.io
      *

      {info:title=Make Note}

      As of this writing the latest Redis version is 2.2.7. Ensure you are installing the appropriate Redis version before

      proceeding.

      {info}

       

    3. tar xzf redis-2.2.7.tar.gz
    4. cd redis-2.2.7
    5. make
  • Create the “latest version” symlink
    1. cd /opt/redis
    2. ln -s redis-2.2.7 latest
  • Start Redis Server
    1. cd src
    2. ./redis-server

Test CLI interface

  • Open another terminal window to test CLI interface
  1. cd /opt/redis
  2. ./redis-cli -h localhost -p 6379

Setup Redis Service Management

  • Create the file /etc/init.d/redis and enter the script commands below:
    #!/bin/sh
    #
    # redis this script starts and stops the redis daemon
    #
    # chkconfig: - 85 15
    # description: redis is a non-relational database storage system.
    # processname: redis
    # config: /opt/redis/latest/conf
    # binary: /opt/redis/latest/src/redis-server
    
    PATH=/opt/redis/latest/src:$PATH
    NAME=redis
    
    test -x $DAEMON || exit 0
    
    set -e
    
    case "$1" in
      start)
            echo -n "Starting Redis... \n"
            echo  "\n"
             /opt/redis/latest/src/redis-server &> /dev/null &
            RETVAL=$?
            echo
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/redis
            ;;
    stop)
            echo -n "Stopping Redis... \n"
            echo  "\n"
            #killall -q /opt/redis/latest/src/redis-server
            /opt/redis/latest/src/redis-cli -p 6379 shutdown
            RETVAL=$?
            echo
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/redis
            ;;
          *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop}" >&2
                exit 1
                ;;
        esac

     

  • chmod +x /etc/init.d/redis
  • chkconfig –add redis
  • chkconfig redis on
  • service redis stop
  • service redis start