How to Install Redis and phpredis on Ubuntu

MooseLucifer

Well-known member
Registered
Joined
May 20, 2016
Messages
149
Points
28
Redis is an in-memory cache like memcached, which is stored in RAM for faster access than other types of cache on your hard disk, but Redis supports caching better than memcached, it supports many types of structures as String. hashes, lists, sets, etc and it is a perfect replacement for Memcached to use for blogs and websites.

Preparations before installing

Updatethe library:
Code:
sudo apt-get update
Set compiler (if not already)

Code:
sudo apt-get install build-essential
Set tcl
Code:
sudo apt-get install tcl8.5
Install Redis

Download the latest Redis

Code:
wget http://download.redis.io/releases/redis-stable.tar.gz
Unzip to a folder and move the unzipped

Code:
tar xzf redis-stable.tar.gz
cd redis-stable
Run this command to install :

Code:
sudo make install
Once installed Redis, we get a script file that allows Redis background. To use this script, moved to a folder utils

Code:
cd utils
Run Ubuntu/Debian install script:

Code:
sudo ./install_server.sh
When this script has run, it will run Redis-server platform. Can use the following command to start/stop:

Code:
sudo service redis_6379 start
sudo service redis_6379 stop
(Number 6379 depends on the port you use, the default is 6379)

If commands above have not set yet then run this command:

Code:
sudo update-rc.d redis_6379 defaults
Install phpredis

Download source

Code:
wget https://github.com/phpredis/phpredis/archive/develop.zip
If using PHP7 then at this time there is a package:

Code:
wget https://github.com/phpredis/phpredis/archive/php7.zip
Unzip the downloaded file, move to the newly unzipped folder and run the following command to install:

Code:
sudo phpize
sudo ./configure
sudo make
sudo make install
If file extension didn't install right folder, copy the file redis.so in modules folder into PHP extensions directory. Then add the following to your php.ini file:

Code:
extension = redis.so
Use phpredis

For example, connect to Redis server:

Code:
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
try {
    $redis->ping();
} catch(RedisException $e) {
    echo 'Error: ' .  $e->getMessage();
    exit;
}

echo 'Server is running';
For example, using phpredis simply:

Code:
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
try {
    $redis->ping();
} catch(RedisException $e) {
    echo 'Error: ' .  $e->getMessage();
    exit;
}

$redis->set('name', 'Maria');
echo $redis->get('name');
Documents using Redis and phpredis at GitHub

Code:
http://redis.io/documentation
https://github.com/phpredis/phpredis
If you have any other ways to install Redis and phpredis on Ubuntu, please write down. I look forward to reading all your comments.
 
Newer Threads
Replies
1
Views
4,000
Replies
14
Views
7,014
Replies
6
Views
5,482
Latest Threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top