Web Hosting Forums

Results 1 to 10 of 10

This is a discussion on SSH2 Function (PHP) in the Hosting Talk & Chit-chat forum
Hi Guys, a little question: I want to use SSH function that JagPc had notice us like "installed" on our server. When i try to ...

  1. #1
    Loyal Client
    Join Date
    May 2006
    Location
    Italy
    Posts
    66

    SSH2 Function (PHP)

    Hi Guys, a little question:

    I want to use SSH function that JagPc had notice us like "installed" on our server.

    When i try to launch a simple , i obtain an undefined call function..someone can help me?

    $port = 2211;
    $ip = 'example.com';
    $connection = ssh2_connect($ip,$port);

    What is wrong?
    We want to use ssh via php to backup automatically our sql database, executing a ssh command like mysqldump....

  2. #2
    Banned JPC-Veena's Avatar
    Join Date
    Sep 2002
    Posts
    565
    Hi Matteo,

    If you are trying to connect to ssh on an external server on a port other than 22, it might need that port opened specifically for outbound connections in the server firewall. Please open a support ticket and we can assist you.

  3. #3
    Loyal Client
    Join Date
    May 2006
    Location
    Italy
    Posts
    66
    It's a php file with that code (just for test)on our server...it's not an external connection...

    normally we backup our database via ssh command (terminal) and now we want to use a simple php routine (with ssh function) to automatically exec a simple dump command (obvioulsy with the same port ,ip and command used with terminal connection)

    We have just open a ticket, jagpc have only asnwer about support php-ssh library that is currently supported by jag server...

  4. #4
    CTO JPC-Masood's Avatar
    Join Date
    Aug 2002
    Location
    Jaguar Servers
    Posts
    1,916
    Quote Originally Posted by Matteo Sacco View Post
    i obtain an undefined call function..someone can help me?
    Because ssh functions are not built into php. You need pecl ssh2 package.
    [COLOR="DarkRed"]Masood N. [/COLOR] | [COLOR="Red"]Chief Technical Officer[/COLOR][SIZE="3"] JaguarPC.com[/SIZE]

  5. #5
    Loyal Client
    Join Date
    May 2006
    Location
    Italy
    Posts
    66
    LOL

    on my ticket open JagPc have notice me that ssh functions is supported on our server...but i think that we need to install PECL...or libssh

    Right, after download PECL how can install on our server? Someone can help me? it' a simple "include" or we must do something?

  6. #6
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Are you on an shared or SDX server (since you posted in that thread)? If so, you won't be able to install PECL packages yourself--support has to do it for you.

    If you are on a VPS or dedicated server you can install your own packages, as outlined below.

    PECL packages are PHP extensions, so once downloaded and installed the functions they provide should become php native functions, just like the mysql_* functions are, for example. There isn't anything you should have to do.

    The steps to install a PECL package are:

    1. Run the install command (assuming that you have PEAR installed on the server already):
    Code:
    pecl install packagename
    2. Enabling the new extension in php.ini:
    Code:
    extension=packagename.so
    If you are running mod_php you will also need to restart Apache for the change to take effect. If you are running PHP as a CGI then the change should take as soon as your run your next PHP script.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  7. #7
    Loyal Client
    Join Date
    May 2006
    Location
    Italy
    Posts
    66
    Ok, Jason...i understand (my server is shared... but i have thinked that jagpc see that from my ticket)

    What do you suggest to me to create a simple "php-auto-backup" about my sql-table?

  8. #8
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    The confusion is propbably that ssh itself is installed (and ssh access available), but the extension that makes ssh useable from php is not.

    You're approach is ok. You could ask support if they'd install PECL SSH2 on the server for you. Quite thinkable they're willing to do that; neither of the two JPC officials posting here yelled 'no go' .

    If not, perhaps you have the option of connecting and fetching from the other end? Or you could use a shell script instead of a PHP one.
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

  9. #9
    Loyal Client
    Join Date
    May 2006
    Location
    Italy
    Posts
    66
    Can we use on shared server the mysqldump php function?

  10. #10
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Going back and rereading your original post, I think you may be over-complicating things. If I understand you correctly, you currently log in to your JPC shared server via SSH and execute a command to dump your database to a file (presumably MySQL dump). Now you want to move this functionality to PHP so that you can automate the process. Am I correct?

    If so, you can completely forget about SSH. SSH is just a way to get remote access to the server's command line. PHP already has access to the command line, so starting an SSH session from PHP is unnecessary.

    I'm not exactly sure what you are already doing on the command line, but I'd assume you are using a command that looks something like this:

    Code:
    mysqldump -uUSERNAME -p TABLENAME >backup.sql
    With PHP you can pass that command to the exec() function to run it and achieve the same result:

    PHP Code:
    <?php
        exec
    ('mysqldump -uUSERNAME -pPASSWORD DBNAME");
    ?>
    Note that since you don't have an interactive login with PHP you need to specify your password on the command line. This is insecure because the list of running processes (and anything passed on the command line) can be seen by other users.

    To get around this, you may consider creating a file called .my.cnf (yes, there is a period at the beginning) in your home directory (/home/USERNAME) that contains your password. There are several threads on this forums that discuss this file, just do a search for ".my.cnf" and you'll find several hits.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •