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

Gogs+Jenkins+Docker automated deployment of .NetCore steps

Table of contents Environmental Description Docke...

CSS mimics remote control buttons

Note: This demo is tested in the mini program env...

Solutions to common problems using Elasticsearch

1. Using it with redis will cause Netty startup c...

VMware virtual machine three connection methods example analysis

NAT In this way, the virtual machine's networ...

Implementation steps for docker-compose to deploy etcd cluster

Table of contents Write docker-compose.yml Run do...

Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5

Use the following command to check whether MySQL ...

Solution to MySQL 8.0 cannot start 3534

MySQL 8.0 service cannot be started Recently enco...

HTML uses marquee to achieve text scrolling left and right

Copy code The code is as follows: <BODY> //...

Detailed tutorial on installing nacos in docker and configuring the database

Environment Preparation Docker environment MySQL ...

Detailed explanation of non-parent-child component communication in Vue3

Table of contents First method App.vue Home.vue H...

Rules for registration form design

I finished reading "Patterns for Sign Up &...

Use Docker to run multiple PHP versions on the server

PHP7 has been out for quite some time, and it is ...

Vue.$set failure pitfall discovery and solution

I accidentally found that Vue.$set was invalid in...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...