Home >Backend Development >PHP Problem >How to install redis and php extensions under lunix

How to install redis and php extensions under lunix

PHPz
PHPzOriginal
2023-03-28 15:45:451122browse

Redis is an open source, high-performance key-value storage system that is widely used in web development, message queues, counters and other scenarios. When using Redis, you may need to integrate it with PHP so that you can use Redis more conveniently. This article will introduce how to install Redis and PHP extensions under Linux.

  1. Installing Redis

First, you need to install Redis in the Linux system. The installation can be completed through the following command:

sudo apt-get install redis-server

After the installation is completed, you can use the following command to check whether the Redis service has been started:

sudo service redis-server status

If the service has been started, results similar to the following will be output. :

redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-10-27 11:17:38 CST; 2 days ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
  Process: 4187 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 4188 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 4223 (redis-server)
    Tasks: 4 (limit: 4915)
   CGroup: /system.slice/redis-server.service
           └─4223 /usr/bin/redis-server 127.0.0.1:6379
  1. Install PHP extension

After installing Redis, you need to install the Redis extension integrated with PHP.

First you need to confirm that PHP has been installed. You can use the following command to check:

php -v

If PHP is already installed, you can use the following command to install the Redis extension:

sudo apt-get install php-redis

After the installation is complete, you need to add the Redis extension to the PHP configuration file. You can use the following command to open the PHP configuration file:

sudo vi /etc/php/7.0/apache2/php.ini

Find the following content in the opened configuration file:

;extension=redis.so

Remove the semicolon to enable the Redis extension:

extension=redis.so

Save the file and exit. Next, you need to restart the Apache server for the update to take effect:

sudo service apache2 restart

After completing the above steps, the Redis extension has been integrated into PHP, and you can happily use Redis for development!

Summary

Through the above introduction, we understand how to install Redis and PHP extensions under Linux systems. This will facilitate our subsequent use of Redis and also allow us to better develop PHP applications.

The above is the detailed content of How to install redis and php extensions under lunix. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn