Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while installing libsodium in PHP 7.1

I'm in PHP 7.1.25 and mcrypt is the current extension used and mcrypt will be deprecated in PHP 7.2 and Libsodium will be added to the core extensions in PHP 7.2

Now I would need to try installing libsodium in PHP 7.1 and see how it works, Followed this https://lukasmestan.com/install-libsodium-extension-in-php7 but the installation failed. Updated PECL package as well. See the error below!

Any help would be really appreciated. Thanks in Advance!

$ 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
like image 506
VenkateshLB Avatar asked Dec 26 '18 07:12

VenkateshLB


1 Answers

This did not work for me (Ubuntu 16.04) (to get $ pecl install -f libsodium working):

$ apt install libsodium libsodium-dev

Here I got the following error:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libsodium

What worked instead is downloading libsodium manually and compiling it:

Download libsodium source and unpack

$ wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz
$ tar -xzf LATEST.tar.gz

Compile libsodium

$ cd libsodium-stable/
$ ./configure
$ make && make check
$ make install

See: https://libsodium.gitbook.io/doc/installation

Afterwards the libsodium installation via PECL worked:

$ pecl install -f libsodium

Troubleshooting:

$ pecl install -f libsodium is still not working

Check if PECL is installed:

$ pecl version
PEAR Version: ...
PHP Version: ...
Zend Engine Version: ...
Running on: ...

If you get an error instead you have to install PECL first:

$ apt install php-pear

Check if phpize is available (to compile libsodium for PHP):

$ phpize --version
Configuring for:
PHP Api Version:         20160303
Zend Module Api No:      20160303
Zend Extension Api No:   320160303

If you get an error instead you have to install php7.1-dev:

$ apt install php7.1-dev

How to activate sodium in PHP?

You only have to create a file sodium.ini in your PHP extension directory (probably in /etc/php/7.1/mods-available/)

Content:

extension=sodium.so

You can activate the module via:

$ phpenmod -v 7.1 sodium

(Deactivation can be done via phpdismod -v 7.1 sodium.)

phpinfo should list the module now:

$ 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
like image 121
KatharinaSt Avatar answered Sep 28 '22 03:09

KatharinaSt