Skip to main content

Setup Redis and Redis PHP Client in Ubuntu


Redis is a key-value pair storage system. In this tutorial we will discuss how to install redis and redis php client in ubuntu server.

Prerequisites

1) Ubuntu Server with running LAMP Server.
2) Sudo Permission

Install Redis Server


1) Add PPA repository by running below command and press ENTER
sudo add-apt-repository ppa:chris-lea/redis-server
2) Update your package manager
sudo apt-get update
3) Install Redis Package
sudo apt-get install redis-server
4) Check Redis is running successfully by executing following command
redis-cli ping
This will return PONG if its working correctly.

5) To setup password to your redis server, do below code(not mandatory)
sudo vim /etc/redis/redis.conf
uncomment line containing requirepass and add your password after the keyword
requirepass yourpassword
6) Now restart your redis server
sudo service redis-server restart
7) Try below command to login to your redis server
redis-cli -a yourpassword
output
127.0.0.1:6379>
127.0.0.1:6379> keys *
 (empty list or set)

Now your redis server is successfuly setuped in your ubuntu server.

Install Redis PHP Client


1) Check your php version
php -v

If php version is 5.*

2) Install required package
sudo apt-get install php5-dev
3) Download PHPRedis
cd /tmp
sudo wget https://github.com/phpredis/phpredis/archive/master.zip -O phpredis.zip
4) Unpack, Compile and Install RedisPHP
sudo unzip -o /tmp/phpredis.zip && mv /tmp/phpredis-* /tmp/phpredis && /tmp/phpredis && phpize && ./configure && make && make install
5) Now add your PHPRedis to your PHP 5.*

If your PHP version is greater than 5.5 do below code
sudo touch /etc/php5/mods-available/redis.ini && extension=redis.so > /etc/php5/mods-available/redis.ini
sudo ln -s /etc/php5/mods-available/redis.ini /etc/php5/apache2/conf.d
sudo ln -s /etc/php5/mods-available/redis.ini /etc/php5/fpm/conf.d
sudo ln -s /etc/php5/mods-available/redis.ini /etc/php5/cli/conf.d
If your PHP Version is less than 5.3-5.4, do below code
sudo touch /etc/php5/conf.d/redis.ini && extension=redis.so > /etc/php5/conf.d/redis.ini
If php version is 7

2) Install required package
sudo apt-get install php7.0-dev
3) Download PHPRedis
cd /tmp
sudo wget https://github.com/phpredis/phpredis/archive/php7.zip -O phpredis.zip
4) Unpack, Compile and Install RedisPHP
sudo unzip -o /tmp/phpredis.zip && mv /tmp/phpredis-* /tmp/phpredis && cd /tmp/phpredis && phpize && ./configure && make && make install
5) Add PHPRedis to PHP 7
sudo touch /etc/php/mods-available/redis.ini && extension=redis.so > /etc/php/mods-available/redis.ini
sudo ln -s /etc/php/mods-available/redis.ini /etc/php/7.0/apache2/conf.d/redis.ini
sudo ln -s /etc/php/mods-available/redis.ini /etc/php/7.0/fpm/conf.d/redis.ini
sudo ln -s /etc/php/mods-available/redis.ini /etc/php/7.0/cli/conf.d/redis.ini
6) Run PHP-FPM

if PHP 5.*
sudo service php5-fpm restart
if PHP 7
sudo service php7.0-fpm restart
7) Restart apache server
sudo service apache2 restart
8) Check PHPRedis installed by trying below command in command line. If success, it will print OK
php -r "if (new Redis() == true){ echo \"OK \r\n\"; }"

Popular posts from this blog

Implementing Client Side WebRTC using Sipml5 javascript

Step 1:

Download and require Sipml5 library function.

Step 2:

Initialize sipml5 Engine in your web page :

var readyCallback = function(e) {
// function called when sipml is successfully initialised.
createSipStack(); // calling this function to create sip stack(see below)
};

var errorCallback = function(e) {
// function called when error occured during sipml initialisation.
};

SIPml.init(readyCallback, errorCallback);

Step 3:

Create Sip Stack :-
Sip Stack is an object that must be created before making/receiving call and sms. Creating Sip stack is an asynchronous process, so you need to create an event listener function to get state change notification.

var sipStack;

function EventListener(e) {

/*
* e.type ;type of event listener
* e.session ; current event session
* e.getSipResponseCode() ; event response code
* e.description ; event description
*/

if(e.type == 'started'){
// successfully started the stack.
register();
} else if(e.type == 'i_new_call'){
// when new incoming call comes.
      …

Setup Asterisk 13 with FreePBX 13 in CentOS 7

Launch CentOS 7 AWS Ec2 InstanceLog in to your aws consoleGo to ec2 management page and click Launch Instance on Instance pageIn Choose AMI step, go to AWS MarketPlace tab and search CentOS 7 on search field. List of centos 7 ami's will be available.Select CentOS 7 (x86_64) ami which is free tier eligible. Select your instance type and click configure instance. Keep default values from Configure Instance to Add Tags stepsIn configure security group, create a security group which allow minimum ports openSSH : port 22HTTP : port 80Custom UDP Rule : 10000-20000 (if you are giving RTP ports 10000-20000)Custom UDP Rule : 5060 (ChanSIP port)Custom TCP Rule : 5060 (ChanSIP Port)Click Launch Instance. Select your key file and accept terms to launch instance.
Setup CentOS Server SSH into newly created CentOS server with username centos and your key file.Update all existing packagessudo yum update -yNow start http service(you can access your server via browser by going to your server ip addres…

MULTIPLE FILE UPLOAD USING AJAX WITH PROGRESS BAR

Uploading multiple files using ajax makes a pleasant feeling to the user. It makes even more happier if upload progress status is printed with percentage.

            In this blog, you will make a file upload form using ajax with file upload progress bar.

Prerequisites :

1) Javascript supported browser
2) LAMP Server / XAMPP Server

Code :

index.html

<!DOCTYPE html>
<html> <head><title>Multiple File Upload using Ajax</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script> </head> <body><div><form action="action.php" method="post" enctype="multipart/form-data" id="multiple-upload-form"><input type="button" id="select-file-btn" value="Select Files" onclick="document.getElementById('files').click(); return false;&qu…