Home >Backend Development >PHP Tutorial >Steps to install php Redis extension on Homestead and solve problems encountered

Steps to install php Redis extension on Homestead and solve problems encountered

不言
不言forward
2018-10-09 15:16:273240browse

The content of this article is about the steps to install the php Redis extension on Homestead and the solutions to the problems encountered. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Recently after using vagrant to install homestead, when running the code, it was prompted that the corresponding Class for Redis did not exist. In fact, it was due to the lack of the corresponding PHP Redis extension. I encountered many pitfalls during the installation process, which was recorded in this article. Inside

First enter homestead through vagrant ssh

Download & compile the PHP Redis extension

git clone https://github.com/phpredis/phpredis.git
cd phpredis                  
/usr/bin/phpize5.6  (不同php版本的情况phpize版本不同)
./configure --with-php-config=/usr/bin/php-config5.6 (这里边也需要根据情况指定 php-config 的版本,且和 phpize 的版本保持一致。)
make && make install

. {note} After the compilation is completed, the redis PHP extension is in the module directory. Its file name is redis.so*

Check the extension_dir of PHP. There are many ways:

1. One is to prompt the installation directory of the extension when the installation is completed, as shown below

Steps to install php Redis extension on Homestead and solve problems encountered

2. Use the command php -i|grep extension_dir

to move the redis.so extension module into the PHP extension directory

<code>sudo mv ./modules/redis.so /usr/lib/php/2013122<br/></code>

Add the ini file of the PHP configuration file

<code>创建一个文件<br/>sudo touch /etc/php/5.6/fpm/conf.d/20-redis.ini<br/>使用vi编辑器写入如下内容:<br/>extension=redis.s<br/></code>

All is well, restart php- fpm

<code>sudo service php5.6-fpm restart<br/></code>
When you use phpinfo() on the web page again, you will find that the redis extension appears and new Redis() is available.

Let’s talk about the main pitfalls

When executing phpize related commands, the prompt is not found. There are php5.6, php7.0, php7.1, and php7 in homestead. 2. Based on what I used This situation only occurs with php5.6. You need to install php-dev. When you use sudo apt install php-dev, it prompts that the corresponding package cannot be found. If you execute apt search php-dev, you cannot find it. You must use apt search php5.6. -dev can get the corresponding package address (I accidentally executed apt search php5 and then found out that the corresponding package name is php5.6-dev). After knowing the package name, I can directly use sudo apt install to install the corresponding package.

The above is the detailed content of Steps to install php Redis extension on Homestead and solve problems encountered. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete