I've looked through the others that use these words. Not applicable. I have two machines plugged into the same switch with IP's of 192.168.0.7 and .10. 7 is the client. 10 is the server. I've checked netstat on the server and it is showing:
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.0.10:3306 0.0.0.0:* LISTEN
I can ping, sftp and so forth in both directions from either machine. The PHP itself is as follows:
$host = "192.168.0.10";
$user = "web";
$pass = redacted;
$db = "appliance";
// open connection
$connection = new mysqli($host, $user, $pass, $db);
if ($connection->connect_errno) {
echo "Error: Failed to make a MySQL connection, here is why: \n";
echo "Errno: " . $connection->connect_errno . "\n";
echo "Error: " . $connection->connect_error . "\n";
exit;
}
I get this at the browser (3rd machine - same network):
Error: Failed to make a MySQL connection, here is why: Errno: 2002
Error: No route to host
I've even tried adding the explicit port argument. Same error.
I don't even know where to look at this point.
Can You execute this code in both CLI and HTTP environment?
If apache has problem, therefore in cli there was no problem.
Check if the firewall on your MySQL server is blocking port 3306. For me it caused the 'No route to host' error.
check your connection to remote and check remote's firewall.
and check bind address in remote my.ini
Related
I am trying to use a simple PHP connection to connect remotely to a MySQL database. I have searched many threads and still receiving error 'Connection failed: Can't connect to MySQL server on 'my IP address' (111 "Connection refused")'
I can access the server remotely using the wan IP address no problem i.e. The software files. I am using port forwarding to do that on port 80.
My connection is very simple
<?php
$servername = "my ip address";
$username = "user";
$password = "password";
$dbname = "company";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, name FROM table";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
I have tried the following;
Creating a new user with all privileges in phpMyAdmin and using % as host
Allow from all in phpmyadmin.conf and HTTP.conf (don't think this is the problem)
Adding port forwarding on router to 3306
Disabled all firewalls on local machine
Adding bind-address = 0.0.0.0 to my.ini file (restarting the server)
A lot of thread suggest that the default bind-address is set to localhost or 127.0.0.1 but in my.ini under [mysqld] all I have from default is
default_authentication_plugin=mysql_native_password
port = 3306
I am using WAMP version 3.1.9 64 bit version
Separate your concerns.
First, verify that another machine on your local network can access the database directly at the 3306 port. This will verify that the server is working, that the log in is correct, and that the permissions are correct, and that any firewall settings have been addressed.
After all is working correctly, deal with accessing it via WAN. It's unclear if you're attempting to do this "from inside the house", ie, using your own external WAN ip address from yourself, there are multiple ways this can fail. It can work, but that's additional setting/debugging. So ensure you're dealing with a machine that's actually outside your network for this section of the testing.
As it stands, somewhat impossible to know where the trouble lies.
After trying everything I set up another WAMP installation on a separate machine and connected to a separate network. I could get it to connect to the remote MYSQL on my original machine. It appears that the PHP script was blocked by cPanel before the request was even sent. The link here https://docs.cpanel.net/knowledge-base/general-systems-administration/how-to-configure-your-firewall-for-cpanel-services/84/ shows that cPanel does not allow outbound connection on port 3306. Unfortunately I can't access settings on my shared hosting to change this.
<?php
$servername = "192.168.179.130";
$username = "root";
$password = "";
$dbname = "rawcdr";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
The above code gives a warning Warning: mysqli::mysqli(): (HY000/2002) A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\new_table\index.php on line 59.
The host is a different server (CentOS 7), and i have checked its reach ability.
I have also provided special privilege in mysql server by:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.%' IDENTIFIED BY PASSWORD '';
Also started the firewall service by:
service firewalld start
Checked the port 3306 is open by following command:
netstat -nlp | grep 3306
Of course the first thing to check is that the firewall on the remote machine is not blocking access on port 3306.
But:
The root user account on a MYSQL Server is by default configured so that this account can only be used from the machine running the MySQL Server instance. So by default you cannot use root to access the server remotely.
And that is as it should be. It is afterall the SuperUser account.
EG
`root`#`localhost`
So you are going to have to create a new user on the remote MYSQL Server instance that is allowed to connect from either any remote host dangerous or a specific remote host (your PC's ip address). This new account should also be setup to be allowed access with the required privilages on the database you are trying to access.
CREATE USER 'ayax'#'192.168.1.200' IDENTIFIED BY 'new_password'
Or if its 5.7 server dont forget the new password expire
CREATE USER 'ayax'#'your-ip-address' IDENTIFIED BY 'new_password'
PASSWORD EXPIRE NEVER;
If your ip address is allocated by a DHCP server and can change from day to day something like this would be more flexible
CREATE USER 'ayax'#'192.168.1.%' IDENTIFIED BY 'new_password'
Try this :
$conn = mysqli_connect('192.168.179.130', 'my_user', 'my_password', 'my_db');
if (!$conn) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
Hi guys i m trying to access my RDS instance from my computer using apache in wamp after fiddling around i found out about the security group i checked the security group and made it all traffic all ports all ips 0.0.0.0/0 i even tried to make it my ip but when i tried to run a script in my computer the script is
<?php
$conn = new mysqli("xxxxxxxxxxxxxxxxxxxx.rds.amazonaws.com","xxxxxxxxx","xxxxxx","xxxxx");
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
else
{
echo "yess";
}
?>
this gave me error "Connection failed: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. "
what to do? any idea would be appreciated.
I've got here an Windows Server 2008r2 set up with Active Directory, DNS, DHCP and DC for testing purposes and i am quite new to LDAP.
I want to change the password for myself, even though if i am no
admin.
So, here is my script i am working on right now:
// LDAP Variables
$serverip = "192.168.2.1";
$serverport = 636;
$username = "user";
$userpassword = "password1";
$newpass = "password2";
$userDn = "CN=$username,CN=Users,DC=dc-name";
$ldapconn = ldap_connect($serverip, $serverport) or die("LDAP Connection Failed!\n");
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ldapconn) {
echo "Connection succeded\n";
// LDAP Bind
$bindresult = ldap_bind($ldapconn, $username, $userpassword);
if ($bindresult) {
echo "Bind: Succeded\n";
$userData['unicodePwd'] = toPwEntry($newpass);
$modresult = ldap_mod_replace($ldapconn, $userDn , $userData);
if (!$modresult) echo "PW Change Failed - Error No. ". ldap_errno($ldapconn).": " .ldap_error($ldapconn) . "\n";
}
else echo "Bind Failed - Error No. ". ldap_errno($ldapconn).": " .ldap_error($ldapconn) . "\n";
}
else echo "Connection failed - Error No. ". ldap_errno($ldapconn).": " .ldap_error($ldapconn) . "\n";
function toPwEntry($pw) {
return("\"". iconv('UTF-8','UTF-16LE',$pw) ."\"");
}
ldap_close($ldapconn);
when i start the script i get this error:
soenke#work:~/Desktop/$ php ldap.php
Connection succeded
Bind Failed - Error No. -1: Can't contact LDAP server
i also tried connections by using "ldaps://" in front of the ip but it doesn't work.
i would appreciate any help!
A couple of suggestions:
ldap_bind() wants $userDN rather than $username. That would cause a different error message though.
There's no actual network traffic between your web server and the ldap server until you call ldap_bind(), so make sure there aren't any firewall/network issues, etc. The error message says "Can't contact the server"; that might be exactly what's happening. (The ldap_connect() function just initializes a local struct in later versions of ldap libraries. You could think of it more like "ldap_init()" -- the "Connection succeeded" message doesn't imply a successful network connection here.)
You can setup an LDAP server to handle both secure and insecure connections on 389 instead of 636. Make sure you're connecting where the server expects you to.
These symptoms might also show up if your end of the TLS connection fails to verify the server certificate. You either have to provide root certificates to trust, or configure your client to not verify the cert (if the server has a self-signed certificate, for example). Either of those can be accomplished by setting variables in an ldap.conf file. Where to put ldap.conf depends on your web server setup.
This: http://www.novell.com/coolsolutions/tip/5838.html and this: http://www.whatsnoodle.com/php-ldap_bind-gives-the-error-cant-contact-ldap-server/ might have more details for you.
Active Directory will only let you change passwords via LDAPS and I'm pretty sure you have to use port 636.
When you specify LDAPS:// try it in upper case. At least one of the MS provider monikers is case-sensitive. I'm not completely sure it's the LDAP one; I've used caps for all monikers for years.
Your password, I think, has to be an octet string (byte array). I can't read PHP so I can't tell if that's what you're doing but I'm guessing so.
Your domain controller will need a certificate to do LDAPS. I'm no certificate expert but I think the name you use for the server has to match the one on the certificate and it's not normally the IP address (though I think you can put them in alternate names on the cert) so I think you should be using the server name.
I am trying to connect to the database that is hosted on my server through my local machine.
my server has cPanel 11, and it is a typical shared server, powered by CentOS, PHP and MySQL installed.
to be precise i am holding the reseller account in the same server. i want to access the database between different accounts or domains.
in MySQL connection String i tried defining the domain name, and it isn't working. here is what i tried.
<?php
$link = mysql_connect('mydomain.com', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
this is giving the following error
Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://bhatkalnews.com:3306) in C:\wamp\www\test\conn.php on line 4
Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\test\conn.php on line 4
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\test\conn.php on line 4
what do i have to define in connection string to make it work?
Firewall ?
try
telnet mydomain.com 3306
on the command line.
If that doesn't work, the connection is blocked by a firewall, most likely
Did you try adding the port explicitly:
mysql_connect('mydomain.com:3306', 'mysql_user', 'mysql_password');
or the port youre running on if not the default 3306. This of course assumes your server allows remote connections.
Also make sure the user in quest has access from the IP address youre connecting from. This isnt youre issue right now, but it may be the next question you have after you get the server to respond :-)
Please refer,
http://forums.mysql.com/read.php?52,294772
You need to add your IP address/range on Access Host list in Remote MySQL in cPanel.