Easy-one-step install Redis 2.8 (latest) + PhpRedis in Ubuntu from source code

Dec 9, 2013, 9:57:17 PM

redis

Redis is a modern and very fast key-value storage. Someone calls it a "NoSQL" storage, someone - "just a memory cache". And all of them partly right - as Redis is a powerful tool, that could became very effective in different use cases.

Learn Redis

If you are not familiar with Redis at all. Start here - The Little Redis Book by Karl Seguin (Russian version)

Redis gets a lot of updates and new features, that's why in Linux repos you almost always see outdated versions. I recommend to install Redis and php_redis (PHP Redis driver extension) from source - it is very easy and fast.

I have prepared some bash script to do it in one step for Ubuntu.

Install latest Redis from source

One script Gist source

Step-by-Step : Save it to .sh file and execute.

#!/bin/bash

if [ "$(whoami)" != "root" ]; then
 echo "ERROR : Run script as Root (sudo !!) please"
 exit 1
fi

read -e -p "Redis version to be installed (change if needed) : " -i "2.8.8" VERSION
echo 'Installing redis v.'$VERSION' ... '

# installing build essentials if it is missing
apt-get install build-essential

wget http://download.redis.io/releases/redis-$VERSION.tar.gz
tar xzf redis-$VERSION.tar.gz
cd redis-$VERSION
make
make install prefix=/usr/local/bin/
cp redis.conf /etc/redis.conf
cd ..
rm redis-$VERSION -R
rm redis-$VERSION.tar.gz

Add redis-server service

useradd -r -s /bin/false redis
wget -O /etc/init.d/redis-server https://gist.github.com/iJackUA/5336459/raw/4d7e4adfc08899dc7b6fd5d718f885e3863e6652/redis-server-for-init.d-startup
touch /var/run/redis.pid
chown redis:redis /var/run/redis.pid
chmod 755 /etc/init.d/redis-server

Add redis-server to autostart

update-rc.d redis-server defaults

Install PhpRedis from source

PhpRedis is a very fast, effective C extension for PHP that provides API for Redis server.

One script Gist source

Save it to .sh file and execute. It will install all needed PHP dependencies, get latest php_redis, add extension config and relaunch Apache. If you use not Apache2 - then modify script a little to perform actions needed for your server.

#!/bin/bash

if [ "$(whoami)" != "root" ]; then
 echo "ERROR : Run script as Root (sudo !!) please"
 exit 1
fi

read -e -p "php_redis version to be installed (change if needed) : " -i "2.2.5" VERSION
echo 'Installing php_redis v.'$VERSION' ... '

# installing build essentials if it is missing
apt-get install php5-dev php-pear

wget https://github.com/nicolasff/phpredis/archive/$VERSION.tar.gz
tar xzf $VERSION.tar.gz
cd phpredis-$VERSION
phpize
./configure
make
make install
cd ..
rm phpredis-$VERSION -R
rm $VERSION.tar.gz

mv /etc/php5/mods-available/redis.ini /etc/php5/mods-available/redis.bkp
touch /etc/php5/mods-available/redis.ini
echo "extension=redis.so" > /etc/php5/mods-available/redis.ini
ln -s /etc/php5/mods-available/redis.ini /etc/php5/apache2/conf.d/redis.ini
ln -s /etc/php5/mods-available/redis.ini /etc/php5/cli/conf.d/redis.ini

service apache2 restart

Straight and clear

I hope these scripts are quite easy to understand and modify as this is just a set of simple and common operations. But you do not need to repeat them each time you want to update Redis to latest version - just save these scripts and re-run.

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Skaffold tool that facilitates continuous development for Kubernetes-native applications. Continuously deploys to your local or remote Kubernetes cluster.



DoItLive is a tool for live presentations in the terminal. It reads a file of shell commands and replays the commands in a fake terminal session as you type random characters.