6

I use the functions below to copy files from one server to another. It works most of the time, but sometimes I start getting this error in log files:

Module 'ssh2' already loaded in Unknown on line 0

And it stops copying. Later for some reason, the error will stop and copying will start working again. What is the issue here?

function getConn($server,$username,$password)
{
    $connection = 0;

    if (function_exists("ssh2_connect")) 
    {
        $connection = ssh2_connect($server, 3817);
        if($connection)
        {
            if(ssh2_auth_password($connection, $username, $password))
            {
                return $connection;
            }
        }
    }
    return 0;
}
function scp($server,$username,$password,$remotepath,$localpath)
{
    $connection = 0;
    $connection = $this->getConn($server,$username,$password);
    if($connection)
    {
        $ret = ssh2_scp_send($connection, $localpath, $remotepath, 0644);
        ssh2_exec($connection, 'exit'); 
    }
}

3 Answers 3

16

The error message Module 'ssh2' already loaded in Unknown on line 0 means that there's something off in your PHP configuration. Check to see if there's a line that says extension=ssh2.so in your php.ini. If so, remove it and check if everything is still working. Possibly, the extension=ssh2.so is loaded twice, meaning PHP will complain that the module is already loaded.

Good luck.

2
  • We had a case where there two files in the /etc/php.d directory that included the ssh2 module. No idea how that happened, but we removed one of them and all seems well.
    – UncaAlby
    Oct 15, 2019 at 15:23
  • In FreeBSD, you will have /usr/local/etc/php.ini where these things would normally be set, but in addition, the package manager adds module specific ini files under /usr/local/etc/php - e.g. ext-20-ssh2.ini which contains the "extension=ssh2.so" reference. In these cases, remove the references from php.ini or the specific ini file under /usr/local/etc/php (prefer the former) Jun 5, 2021 at 20:34
1

In my case, I commented out the one line in ssh2.ini located here: /etc/php5/mods-available/ssh2.ini

The content of this file now is as follow:

;extension=ssh2.so

Thanks!

0

If the above does not work, take a look inside /etc/php5/conf.d

If you see duplicate ssh2.ini files, remove any extra ones.

In my case I had 50-ssh2.ini and ss2.ini. Both files were providing the line:

extension=ssh2.so

For me removing 50-ssh2.ini solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.