How to install the `sodium` extension if your PHP version hasn't it directly in Ubuntu 22.04?

Prerequisites:

Indeed, the prerequisite packages and dependencies are crucial for successfully installing and configuring the sodium extension in your XAMPP environment. Installing autoconf, libsodium-dev, and ensuring the correct paths and configurations are essential for a successful installation.

If you don't have autoconf then you can download it.

sudo apt-get update
sudo apt-get install autoconf

To install libsodium-dev run the following commands:

sudo apt-get install libsodium-dev

Download the sodium extension source code from the PECL website using the following command:

  •   wget https://pecl.php.net/get/libsodium
    
  • Extract the downloaded archive:

  •   tar -xf libsodium
    
  • Navigate into the extracted directory:

  •   cd libsodium-*
    

    Build and install the extension:

  •   sudo /opt/lampp/bin/phpize
      ./configure --with-php-config=/opt/lampp/bin/php-config
      make
      sudo make install
    
  • Once the installation is complete, you must enable the sodium extension in PHP. Open the php.ini file in a text editor:

  •   sudo nano /opt/lampp/etc/php.ini
    
  • Add the following line at the end of the php.ini file:

  •   extension=sodium
    
  • Save the file and exit the text editor.

  • Restart the XAMPP server:

      sudo /opt/lampp/lampp restart
    

After following these steps, the sodium extension should be installed and enabled in your XAMPP environment. You can verify the installation by running the php -m command, which should display sodium in the list of installed modules without any warning messages.

0
Subscribe to my newsletter

Read articles from MD Shahin Mia Robin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

MD Shahin Mia Robin
MD Shahin Mia Robin

Software Engineer@Datasoft Systems Bangladesh Limited BSc. in CSE