Error while installing libsodium in PHP 7.1
我在PHP 7.1.25中,并且mcrypt是当前使用的扩展,mcrypt将在PHP 7.2中弃用,而Libsodium将被添加到PHP 7.2的核心扩展中
现在,我将需要尝试在PHP 7.1中安装libsodium并查看其工作原理,请遵循https://lukasmestan.com/install-libsodium-extension-in-php7,但安装失败。 同时更新了PECL软件包。 看到下面的错误!
任何帮助将非常感激。 提前致谢!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | $ sudo pecl install -f libsodium downloading libsodium-2.0.20.tgz ... Starting to download libsodium-2.0.20.tgz (28,504 bytes) .........done: 28,504 bytes 4 source files, building running: phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 building in /tmp/pear/temp/pear-build-rootsL5uMO/libsodium-2.0.20 running: /tmp/pear/temp/libsodium/configure --with-php-config=/usr/bin/php-config checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php/20160303 -I/usr/include/php/20160303/main -I/usr/include/php/20160303/TSRM -I/usr/include/php/20160303/Zend -I/usr/include/php/20160303/ext -I/usr/include/php/20160303/ext/date/lib checking for PHP extension directory... /usr/lib/php/20160303 checking for PHP installed headers prefix... /usr/include/php/20160303 checking if debug is enabled... no checking if zts is enabled... no checking for re2c... no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk... gawk checking for sodium support... yes, shared checking for pkg-config... no checking for libsodium... configure: error: Please install libsodium - See https://github.com/jedisct1/libsodium ERROR: `/tmp/pear/temp/libsodium/configure --with-php-config=/usr/bin/php-config' failed |
这对我不起作用(Ubuntu 16.04)(使
1 | $ apt install libsodium libsodium-dev |
在这里,我得到以下错误:
1 2 3 4 | Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libsodium |
相反,有效的方法是手动下载libsodium并进行编译:
下载libsodium源码并解压缩
1 2 | $ wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz $ tar -xzf LATEST.tar.gz |
编译libsodium
1 2 3 4 | $ cd libsodium-stable/ $ ./configure $ make && make check $ make install |
参见:https://libsodium.gitbook.io/doc/installation
之后,通过PECL安装libsodium起作用了:
1 | $ pecl install -f libsodium |
故障排除:
检查是否安装了PECL:
1 2 3 4 5 | $ pecl version PEAR Version: ... PHP Version: ... Zend Engine Version: ... Running on: ... |
如果出现错误,则必须先安装PECL:
1 | $ apt install php-pear |
检查phpize是否可用(为PHP编译libsodium):
1 2 3 4 5 | $ phpize --version Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 |
如果出现错误,则必须安装php7.1-dev:
1 | $ apt install php7.1-dev |
如何在PHP中激活钠?
您只需要在PHP扩展目录(可能在
内容:
1 | extension=sodium.so |
您可以通过以下方式激活模块:
1 | $ phpenmod -v 7.1 sodium |
(可以通过
phpinfo现在应该列出模块:
1 2 3 4 5 6 7 | $ php -i | grep sodium /etc/php/7.1/cli/conf.d/20-sodium.ini, sodium sodium support => enabled sodium compiled version => 2.0.20 libsodium headers version => 1.0.18 libsodium library version => 1.0.18 |
@VenkateshLB您必须首先安装linux发行版提供的libsodium。
CentOS 7:
1 | yum install libsodium libsodium-devel |
Ubuntu 18.04:
1 | apt install libsodium libsodium-dev |
安装后,执行PECL命令。