Home  >  Article  >  Backend Development  >  How to install redis in php7 yum

How to install redis in php7 yum

藏色散人
藏色散人Original
2021-12-30 09:18:093817browse

How to install redis with php7 yum: 1. Install yum source and nginx; 2. Start nginx and set it to run automatically at boot; 3. Check the php7 yum component and install php7.2; 4. Start php and set it up To start at boot; 5. Use the specified yum source to install Redis.

How to install redis in php7 yum

The operating environment of this article: centos7 system, PHP7.2 version, Dell G3 computer.

centos7 nginx php7yum installation, and how to install redis with yum:

1. Install nginx

1. Install yum Source

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2. Install nginx

yum install -y nginx

3. Start nginx and set it to run automatically at boot

 systemctl start nginx  #启动,restart-重启,stop-停止
 systemctl  enable nginx  #开机启动

4. Check the version and running status

 nginx -v  #查看版本
 
 ps -ef | grep nginx  #查看运行状态

2. Install php7

1. Install yum source

 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
 
 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. View the php7 yum component and install php7 as an example. 2

 yum search php72w

3. Select the components you need to install. php72w.x86_64 and php72w-fpm.x86_64 are required for core programs.

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4. Start php and set up Start for boot

 systemctl start php-fpm  #启动,restart-重启,stop-停止
 
 systemctl  enable php-fpm  #开机启动

5. Check the version and running status

 php-fpm -v  #查看版本
 
 ps -ef | grep php-fpm  #查看运行状态

After completing the above steps, the reader can configure the web directory in nginx by himself, and it can run normally , but at this time nginx and php are running as root. Running web files with the highest permissions will bring security risks to the system. The following is an example of permission configuration

3. Modify nginx configuration

vi /etc/nginx/conf.d/default.conf

Find this line in the first location

index  index.html index.htm;

and modify it to:

index  index.php index.html index.htm; #添加index.php

2. Remove the comment of location under the FastCGI server line and modify it to the following Like this

 

   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~ .php$ {
         root            /usr/share/nginx/html;  #网站根目录
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
 }
service nginx restart   #重启nginx
service php-fpm start   #开启php-fpm

3. Create a new index.php file in the root directory of the website

vim /usr/share/nginx/html/index.php

Enter the content:

<?php phpinfo();

5. Enter in the browser Virtual machine IP, you can already see the phpinfo information. Modify the hosts file on Windows and add a line 192.168.6.114 www.test1.com \#Configure the domain name corresponding to the virtual machine IP

6. Now you can Use www.test1.com to access the server configured by the virtual machine

4.yum installation redis

When installing redis with yum, it is recommended to use Remi repository source. Because the Remi source provides the latest version of Redis, you can use YUM to install the latest version of Redis through this source. In addition, the latest yum sources of PHP and MySQL are provided, as well as related service programs.

1) Remi repository source depends on epel source, so you need to install epel source first

[root@youxi1 ~]# yum -y install epel-release

2) Install Remi repository source

[root@youxi1 ~]# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@youxi1 ~]# ls /etc/yum.repos.d/  //下载完成后会出现许多remi的yum源,这里要用到的是remi.repo这个源
CentOS-Base.repo CentOS-Sources.repo remi-glpi92.repo remi-php70.repo remi-safe.repo
CentOS-CR.repo CentOS-Vault.repo remi-glpi93.repo remi-php71.repo
CentOS-Debuginfo.repo epel.repo remi-glpi94.repo remi-php72.repo
CentOS-fasttrack.repo epel-testing.repo remi-modular.repo remi-php73.repo
CentOS-Media.repo remi-glpi91.repo remi-php54.repo remi.repo

3) Use the specified yum source to install Redis

[root@youxi1 ~]# yum --enablerepo=remi install -y redis  //--enablerepo指定yum源
[root@youxi1 ~]# redis-cli --version  //安装完成后使用命令查看一下版本
redis-cli 5.0.5

Note: After the remi source installation is completed, the default is not to start. When you need to use the remi repository source installation program, you need the --enablerepo=remi option to specify that the remi repository source can be used, and then to install.

4) Start Redis and set it to start automatically at boot

[root@youxi1 ~]# systemctl start redis
[root@youxi1 ~]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

Note: The port number of Redis is 6379

[Recommended learning: PHP video tutorial]

The above is the detailed content of How to install redis in php7 yum. 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