Detailed explanation of installation and configuration of Redis and phpredis extension operation in Ubuntu 18.04 system

Detailed explanation of installation and configuration of Redis and phpredis extension operation in Ubuntu 18.04 system

This article describes how to install and configure Redis and phpredis extensions on Ubuntu 18.04. Share with you for your reference, the details are as follows:

1. Installation

Install

$ sudo apt-get update
$ sudo apt-get install redis-server

start up

$ sudo /etc/init.d/redis-server start

Note: If you cannot start

systemctl status redis-server.service
redis-server.service: Can't open PID file /var/run/redis/redis-server
  1. Alibaba Cloud Server, remember to add the service port number in the security group and security policy to allow access from all addresses, that is, all services in Alibaba Cloud Server need to map the port. If this step is not done, the redis-cli command above will be in a waiting state.
    insert image description here
  2. View log information
cat /var/log/redis/redis-server.log
Creating Server TCP listening socket ::1:6379: bind: Cannot assign requested address
  1. IPv6 is disabled on the host, while Ubuntu's redis-server package comes with: bind 127.0.0.1::1
  2. Modify the bind address in the redis configuration file; comment the bind address or change the bind address to 0.0.0.0
vim /etc/redis/redis.conf
bind 127.0.0.1 ::1
  1. Start the redis service (add the configuration file or the configuration will not take effect)
sudo redis-server /etc/redis/redis.conf &
  1. Check services and ports
systemctl status redis-server
netstat -ntpl | grep 6379
2. Check if Redis is running
$ redis-cli

This command will open the following Redis prompt:

127.0.0.1:6379> 

Type ping

127.0.0.1:6379> ping
PONG

Description Successful installation

3. Configure remote login

By default, redis does not allow remote login, so we need to configure it.
Edit the redis configuration file

sudo vi /etc/redis/redis.conf

Comment out the following line, you can search for it

#bind 127.0.0.1

Note: redis-cli -h (ip address) -p (port number defaults to 6379) Note that the parameter should be separated from the specific command by a space.

4. Configure password login

Editing the Configuration File

sudo vi /etc/redis/redis.conf

Find the following line and remove the comment (you can search for requirepass)

#Before modification #requirepass foobared
#After modification requirepass 123456
5. Restart redis
sudo service redis-server restart

Or you can force kill and then manually open

sudo killall redis-server
sudo redis-server /etc/redis/redis.conf &

It is best to add the configuration file here, otherwise the configuration may not take effect.

6. Install the redis extension for PHP
  1. Download phpredis extension file
apt install git 
git clone https://github.com/phpredis/phpredis.git
  1. Move the phpredis folder
mv phpredis /etc/phpredis
  1. Installation (if the execution fails, you need to execute sudo apt-get install php7.2-dev (you can replace dev installation according to the PHP version))
cd /etc/phpredis
phpize
  1. Execute the following three commands
./configure
make
make install
  1. Modify php.ini file
vim /etc/php/7.2/apache2/php.ini

Find and add the following command at the end of the php.ini file

extension=redis.so
  1. Execute the apache2 restart command
/etc/init.d/apache2 restart
  1. Check if the redis extension is installed in PHP
<?php
phpinfo();
?>

insert image description here

I hope this article will help you configure your Ubuntu environment.

You may also be interested in:
  • Detailed tutorial on installing php-fpm service/extension/configuration in docker
  • Detailed steps to install xml extension in php under linux
  • Solve the problem that PHP extension installation does not take effect
  • Detailed installation of PHP environment and extensions on Mac
  • Mac pecl installation php7.1 extension tutorial
  • Detailed explanation of how to install PHP curl extension under Linux
  • How to install PHP7 Redis extension on CentOS7
  • How to install memcache extension in PHP
  • How to install BCMath extension in PHP
  • PHP extension installation method and steps analysis

<<:  Solution to forgetting the root password of MySQL 5.7 and 8.0 database

>>:  Lambda expression principles and examples

Recommend

Introduction to scheduled tasks in Linux system

Table of contents 1. Customize plan tasks 2. Sync...

How to set default value for datetime type in MySQL

I encountered a problem when modifying the defaul...

Postman automated interface testing practice

Table of contents Background Description Creating...

Implementing a shopping cart with native JavaScript

This article shares the specific code of JavaScri...

mysql solves time zone related problems

Preface: When using MySQL, you may encounter time...

Use CSS's clip-path property to display irregular graphics

clip-path CSS properties use clipping to create t...

The HTML 5 draft did not become a formal standard

<br />Yesterday I saw at W3C that the new HT...

Solve the problem that the docker container cannot ping the external network

Today, when I was building a redis environment in...

Basic usage of JS date control My97DatePicker

My97DatePicker is a very flexible and easy-to-use...

Detailed explanation of Nodejs array queue and forEach application

This article mainly records the problems and solu...

Sample code using vue-router in html

Introducing vue and vue-router <script src=&qu...

Application of Beautiful Style Sheets in XHTML+CSS Web Page Creation

This is an article written a long time ago. Now it...

10 HTML table-related tags

In fact many people will say “I’ve seen that table...

Web Design Tutorial (2): On Imitation and Plagiarism

<br />In the previous article, I introduced ...