Reasons which cause remote server fail
1) Server is not up.
Solution:--- Ensure that server is up, before remote connection(telnet serverIP).
2) Mysql uses different port than default.
Solution:-- check for mysql configuration file(my.conf), it hast entry for port used for database connection, if it is other than default(3306), try connecting with port specified in file.
3) Privileges are not granted for remote access on database.
Solution:--
· You need the root or mysql username and password to log in to MySQL using Telnet or an SSH client. This then allows you to perform queries at the command prompt. At the command prompt, type
mysql -u username -p
Enter password when prompted.
Once logged in, you can list all available databases by typing :
SHOW DATABASES;
You can set up database to allow connections from only the server it resides on (localhost), from a specific domain (remotedomain.com) or from any domain except localhost(%).
GRANT ALL PRIVILEGES ON databasename.* TO user@localhost IDENTIFIED BY "password"
GRANT ALL PRIVILEGES ON zingaya.* TO root@serverIP IDENTIFIED BY "password"
GRANT ALL PRIVILEGES ON databasename.* TO user@"%" IDENTIFIED BY "password"
· If you modify the grant tables manually (using INSERT, UPDATE, etc.), you should execute a FLUSH PRIVILEGES statement to tell the server to reload the grant tables
· If earlier step does not work:------
Locate file my.conf(if not this you may find my-small.conf, my-medium.conf, my-large.conf, my-huge.conf) and chage following things:--
Make sure line skip-networking is commented (or remove line) and add following
line bind-address=YOUR-SERVER-IP
Where,
a) bind-address : IP address to bind to.
b) skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should removed from file or put it in comment state.
· Restart your mysql service to take change in effect:
# /etc/init.d/mysql restart
· For testing, from remote system or your desktop type the command:
$ mysql -u user –h remote_serverIP –p
4) Host from which you are connecting is not allowed to access that machine.
Solution:-- For this, look at /etc/hosts.allow and /etc/hosts.deny.
/etc/hosts.allow are hosts that are allowed to connect to said services using tcp_wrappers /etc/hosts.deny are host that aren't allowed to connect to said services using tcp_wrappers.
*
Access will be granted when a (daemon,client) pair matches an entry in the /etc/hosts.allow file.
*
Otherwise, access will be denied when a (daemon,client) pair matches an entry in the /etc/hosts.deny file.
*
Otherwise, access will be granted.
For example:---
# /etc/hosts.deny
ALL:ALL EXCEPT localhost:DENY
ALL:ALL specifies that none is allowed to connect
EXCEPT localhost
EXCEPT localhost
#/etc/hosts.allow
#Allow localhost
ALL : 127.0.0.1
# Allow my other box tr0n to connect to any service
ALL : 192.168.1.2
First line allow any connection to any services from localhost Second line allow any connections to any services from 192.168.1.2
5) Firewall settings are enabled.
Soultion:--
Try connecting using ssh:---
1) From your console you can connect using command:--
for this you need root password,this command is used to create tunnel on remote machine.
once you provide correct password, you can excute shell commands on remote machine from your console
2) From code:--
Accessing remote machine, there is extention provided in php;--
For this you have to copy php_sh2.dll in your php extension folder, restart server,
Then you can you its functions
This library provides you different function for:---
· ssh2_connect -- Connect to an SSH server
· ssh2_tunnel -- Open a tunnel through a remote server
· ssh2_auth_password -- Authenticate over SSH using a plain password
· ssh2_exec -- Execute a command on a remote server
· ssh2_auth_pubkey_file -- Authenticate using a public key
· ssh2_scp_send -- Send a file via SCP