简体   繁体   English

在Ubuntu 14.04上为PHP 7.1安装phpredis

[英]Installing phpredis on Ubuntu 14.04 for PHP 7.1

My php -v 我的php -v

PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:51:39) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans with Zend OPcache v7.1.15-1+ubuntu14.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies PHP 7.1.15-1 + ubuntu14.04.1 + deb.sury.org + 2(cli)(内置:2018年3月6日11:51:39)(NTS)版权所有(c)1997-2018 PHP Group Zend Engine v3。 1.0,版权所有(c)1998-2018 Zend Technologies with Xdebug v2.6.0,Copyright(c)2002-2018,Derick Rethans with Zend OPcache v7.1.15-1 + ubuntu14.04.1 + deb.sury.org + 2,版权所有(c)1999-2018,Zend Technologies

I have tried both the pecl way 我试过pecl方式

sudo pecl install redis
sudo service php7.1-fpm restart

And the manual way from https://github.com/phpredis/phpredis 以及来自https://github.com/phpredis/phpredis的手动方式

phpize
./configure [--enable-redis-igbinary]
make && make install

I made sure to put 我确定放了

extension=/usr/lib/php/20170718/redis.so

into the php.ini file as shown when I run echo phpinfo(); 进入php.ini文件,如我运行echo phpinfo();

eg 例如

/etc/php/7.1/cli/php.ini

When I run the inbuilt web server I get 当我运行内置的Web服务器时,我得到了

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/redis.so' - /usr/lib/php/20170718/redis.so: undefined symbol: zend_empty_string in Unknown on line 0 PHP警告:PHP启动:无法加载动态库'/usr/lib/php/20170718/redis.so' - /usr/lib/php/20170718/redis.so:未定义符号:zend_empty_string在第0行的未知

Strangely PHPStorm autocompletes the PHP Redis class, so 奇怪的是,PHPStorm自动填充PHP Redis类,所以

$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);

I can click into the Redis class and see it is the correct one. 我可以点击进入Redis类,看它是正确的。

I wonder if it is a version difference? 我想知道它是否是版本差异? Maybe because I am using 32-bit? 也许是因为我使用的是32位?

Another strange thing is, if I just put 另一个奇怪的事情是,如果我只是把

extension=redis.so 

in php.ini , it seems to be looking for an older build php.ini ,它似乎在寻找一个较旧的版本

PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/redis.so' - /usr/lib/php/20160303/redis.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP启动:无法加载动态库'/usr/lib/php/20160303/redis.so' - /usr/lib/php/20160303/redis.so:无法打开共享对象文件:未知中的此类文件或目录第0行

When I run 我跑的时候

sudo apt-get install php-redis

it installs and means that no start up error shows, but the web page still shows a 它安装并意味着没有启动错误显示,但网页仍显示

Class 'Redis' not found 找不到“Redis”类

One other thing I notice is that in Apache, there is no error, and the class is found. 我注意到的另一件事是,在Apache中,没有错误,并且找到了类。 But when I run php's inbuilt web server, the not found error shows up. 但是当我运行php的内置Web服务器时,会发现未找到的错误。

您可能需要使用ppa包来安装它,例如:

sudo apt-get install php7.1-redis

Ok so I noticed that phpinfo showed 好的,我注意到phpinfo显示了

PHP API 20160303 PHP API 20160303

which means that the earlier error makes sense. 这意味着早期的错误是有道理的。 The PHP version of the web server is 7.1, however, when running the phpredis phpize it shows the one for 7.2. Web服务器的PHP版本是7.1,但是,当运行phpredis phpize时,它会显示7.2的版本。

So I just made sure to remove php7.2-dev and re-install php7.1 via apt-get, then re-run the github repo steps above. 所以我确保删除php7.2-dev并通过apt-get重新安装php7.1,然后重新运行上面的github repo步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM