Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sgupta1979's avatar

Sodium extension error with PHP 8.1

Hello I upgraded my server with PHP 8.1 with Laravel 10 . I am getting below PHP warning with Laravel php artisan

PHP Warning: Module "sodium" is already loaded in Unknown on line 0

0 likes
3 replies
sgupta1979's avatar

I can not disable it since on the same server another symfony application is running which require sodium. Please suggest

Sergiu17's avatar

Looks like you have multiple declarations of this extension

extension=sodium.so
extension=sodium.so

somewhere is declared twice or more, check you ini files

LaryAI's avatar
Level 58

It seems like the sodium extension is being loaded twice, which is causing the warning message you're seeing. This can happen if the extension is loaded both as a compiled module and through the php.ini configuration file. Here's how you can resolve this issue:

  1. Check Your php.ini File(s): Locate your php.ini file(s) used by the CLI (Command Line Interface). You can find out which php.ini file is being used by running the following command:

    php --ini
    

    This will list all the configuration files used by PHP. Open the php.ini file and look for the line that loads the sodium extension. It might look something like this:

    extension=sodium
    

    If you find such a line, comment it out by adding a semicolon (;) at the beginning of the line:

    ;extension=sodium
    

    Save the file and try running php artisan again to see if the warning persists.

  2. Check for Additional Configuration Files: PHP can also load additional .ini files from a separate directory, which is often listed in the output of php --ini under "Scan for additional .ini files in:". Check this directory for any .ini files that might be loading the sodium extension and comment out the relevant lines as described above.

  3. Recompile PHP (if applicable): If you have compiled PHP from source and included the sodium extension, make sure you haven't also tried to load it via php.ini. If you have, you'll need to remove the extension=sodium line from your php.ini file.

  4. Restart Your Web Server: After making changes to your php.ini file(s), you may need to restart your web server for the changes to take effect. Use the appropriate command for your web server to restart it.

    For Apache, it might be something like:

    sudo service apache2 restart
    

    For Nginx, it might be:

    sudo service nginx restart
    

    For PHP's built-in server (if you're using it for some reason):

    php artisan serve
    

After following these steps, the warning about the sodium extension being already loaded should be resolved. If the issue persists, ensure that you're editing the correct php.ini file(s) for the PHP CLI and not just the one used by your web server.

Please or to participate in this conversation.