• xampp
  • sodium: Unable to initialize module

root@ip-184-168-122-73:/opt/lampp/logs# more php_error_log
[24-Jan-2025 09:55:29 UTC] PHP Warning: PHP Startup: sodium: Unable to initialize module
Module compiled with module API=20190902
PHP compiled with module API=20220829
These options need to match
in Unknown on line 0
[24-Jan-2025 09:55:29 UTC] PHP Warning: PHP Startup: sodium: Unable to initialize module
Module compiled with module API=20190902
PHP compiled with module API=20220829
These options need to match
in Unknown on line 0

The error indicates a mismatch between the PHP API version of the sodium extension and the version of PHP installed in your XAMPP environment. Specifically:

  • The sodium module is compiled with API=20190902 (PHP 7.4.x).
  • Your XAMPP installation uses API=20220829 (PHP 8.2.x).

To resolve this, you need to ensure that the sodium.so file matches the PHP version installed in XAMPP. Here’s how to fix it:


1. Remove the Incompatible sodium.so

  1. Navigate to the XAMPP extensions directory:

       cd /opt/lampp/lib/php/extensions/no-debug-non-zts-20220829/
  2. Remove or rename the existing sodium.so:

       mv sodium.so sodium.so.bak

2. Recompile the Sodium Extension for PHP 8.2.x

Step 1: Install Required Dependencies

Ensure that the necessary development tools and libraries are installed:

sudo apt-get update
sudo apt-get install -y build-essential autoconf libtool libsodium-dev php-dev

Step 2: Download PHP Source Code

Download the exact PHP version source code (8.2.4 in your case):

wget https://www.php.net/distributions/php-8.2.4.tar.gz
tar -xvzf php-8.2.4.tar.gz
cd php-8.2.4/ext/sodium

Step 3: Compile the Sodium Extension

Run the following commands to compile the Sodium extension:

/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make
sudo make install

Step 4: Verify Compilation

After compilation, the sodium.so file will be installed in the correct XAMPP extension directory, typically /opt/lampp/lib/php/extensions/no-debug-non-zts-20220829/.


3. Enable the Sodium Extension in XAMPP

  1. Open the XAMPP php.ini file:

       sudo nano /opt/lampp/etc/php.ini
  2. Add the following line if it’s not already present:

       extension=sodium
  3. Save and close the file (Ctrl + O, Enter, Ctrl + X).


4. Restart XAMPP

Restart XAMPP to load the newly compiled extension:

sudo /opt/lampp/lampp restart

5. Verify the Sodium Extension

  1. Check if the Sodium extension is loaded:

       /opt/lampp/bin/php -m | grep sodium
  2. Verify using phpinfo():

    • Create a file named phpinfo.php in XAMPP’s htdocs directory:
           echo "<?php phpinfo(); ?>" > /opt/lampp/htdocs/phpinfo.php
    • Access it in your browser:
           http://localhost/phpinfo.php
    • Look for a Sodium section.

6. Troubleshooting

  • Error: Still Mismatched API Versions:
    Ensure that you are compiling the Sodium extension with the same PHP version as XAMPP. Verify the XAMPP PHP version with:

      /opt/lampp/bin/php -v
  • Missing Compilation Tools:
    If phpize or other tools are missing, install them:

      sudo apt-get install php-dev

This process ensures that the sodium.so extension matches your XAMPP's PHP version and resolves the error. Let me know if you encounter any issues!