r/PHPhelp • u/trymeouteh • Jun 01 '25
Solved How do you setup Libsodium for PHP 8.3 on Ubuntu/Linux Mint?
I cannot get Libsodium installed or to work with PHP 8.3.6 on Linux Mint 22.1.
I tried to install libsodium and even build libsodium from source but I always get this error when I run the test script to see if libsodium is installed and working in PHP.
Test script...
<?php
var_dump([
\Sodium\library_version_major(),
\Sodium\library_version_minor(),
]);
Error when running script...
$ php script.php
PHP Fatal error: Uncaught Error: Call to undefined function Sodium\library_version_major() in /home/john/Desktop/script.php:4
Stack trace:
#0 {main}
thrown in /home/john/Desktop/script.php on line 4
Is there a way to get libsodium installed on Linux Mint 22.1 or to install it inside a docker container and have it working?
Any advice will be most appreciated.
1
Upvotes
1
u/allen_jb Jun 01 '25
You likely need to install the extension package. While it's bundled with a official PHP source distribution, many distros don't install it by default.
I don't know Linux Mint's package naming, but I'd expect it to be called something like
php-sodiumorphp<version>-sodium. Ask in a distro specific subreddit / forum / chat if you're unsure of package naming.On some distros (Debian/Ubuntu derivatives) you also need to run an additional command (probably
phpenmodto enable the extension after installing the package.You can check what extensions are installed and enabled using
php -m(for commandline) orphpinfo()(for web requests).For
phpinfo()you should see asodium(or the extension name) heading with a table beneath it. Ignore the credits table at the bottom.Note that some distros use separate php.ini files for commandline (cli) and web requests (php-fpm or Apache module). You can check the location of the php.ini file(s) used with
php --ini(commandline) orphpinfo()(web requests - top table)0
u/[deleted] Jun 02 '25
[deleted] — view deleted comment