RDS access from my own computer using apache server - php

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.

Related

SQL Debug Message: 2002) No connection could be made because the target machine actively refused it

I'm getting the almost infamous
(HY000/2002): No connection could be made because the target machine actively refused it
Connection failed: No connection could be made because the target machine actively refused it.
error messages in trying to get PHP to talk to MySQL.
Configure
PHP is 7.3.7 (NTS MSCV15 (Visual c++ 2017) x64)
MySQL is 8.0.17 on a localhost (127.0.0.1)
IIS Windows 10 (10.0.18362.1)
All of this is running locally on laptop at 127.0.0.1 (though the corporate network is a 10.0.?.?)
IT support has spent the best part of 2 hours looking at all network and firewall issues (to the point disabled all firewall and enabled basically all the ports) and nothing seems to get through
MySQL is running, the username and passwords are perfectly fine, the hosts file has a correct DNS entry and the code is correct.
<?php
$servername = "rackforms";
$username = "rackforms";
$password = "????????";
$port = "3312";
// Create connection
$conn = new mysqli($servername, $username, $password, $port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
MySQL port has been deliberately moved to 3312. Use other MySQL instances on 3306. Really it shouldn't make difference.
I've looked at XAMPP and WAMP and other *AMP entries without much luck and spent way too much time on SO.
Any suggestions on what else to do?
Thanks
RESOLVED!!
Need to change the mysql.default_port in php.ini to the same port I am using for MySQL database. Not sure if there is a way to override this port using a connection string as (at least on Windows) seems to be ignored based on comments in php.ini

MYSQL no route to host

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

Why is my php code not connecting to my remote MySql database?

I'm trying to connect to a remote MySql database and I get this error message:
Warning: mysqli_connect(): (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:\myLocalDiectory\RemoteConn.php on line 9 "Resource not found" error 404.
Here's my php file that I'm trying to use:
<?php
define("DB_SERVER", "serverName");
define("DB_USER", "userName");
define("DB_PASS", "password");
define("DB_NAME", "dbName");
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
Am I missing something? Thanks for any help!
The first thing that I would check (if you haven't done so) is that you can in fact connect to the database from the computer that runs your PHP script. This to rule out a network or firewall problem.
The first thing would be pinging the server. In a DOS prompt run:
ping servername
Where "servername" is the same string that you put in your PHP script above. If this does not reply with a string similar to the one below, specifically, the first word is not "Reply":
Reply from 192.168.239.132: bytes=32 time=101ms TTL=124
This means that there is most likely no connectivity between the computer running the PHP script an the mysql server. I would then check if the server and the computer are properly connected to the network, if the server is up, an if there is not firewall in your computer running the PHP script or on the server.
Now, if your test above shows "Reply" to the ping, you can test if you can connect to the Mysql service from your php server. For this you can use Mysql workbench (http://dev.mysql.com/downloads/workbench/) and from there create a connection with the database parameters that you are giving to your script. If you cannot connect with Mysql workbench, you might need to disable a firewall in your Mysql server, a firewall in your computer running PHP, or enable the Mysql server to accept remote connections for the database and username that you use in your PHP script (some distributions Mysql server are installed to only accept local connections for safety).
If the problem is a permission in the server (the user can only connect locally but not from a remote computer for instance), you can enable the permission in the Mysql server with the GRANT command: http://dev.mysql.com/doc/refman/5.1/en/grant.html
define("DB_USER", "userName");
Try root instead of userName and define DB_HOST.

PHP: getaddrinfo failed when trying access a 1&1 database from a local web app

I have an issue when I try to access my 1&1 database from the local web app I am coding.
Output: Failed to connect to MySQL: (2002) php_network_getaddresses: getaddrinfo failed: Unknown host.
I use mysqli (which works great with a local database) to connect my app with the DB and I already know the php5 issue with mysqli and 1&1 servers but this would occurs only if my app where on my server.
$mysqli = new mysqli("dbxxxxxxxxx.db.1and1.com", "dboxxxxxxxx", "xxxxxxx", "dbxxxxxxxx", 3306);
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else
{
$mysqli->set_charset("utf8");
}
Maybe the issue comes from the way I write the host, I tried to add "http://" before but the problem was the same.
Thanks for helping me! :)
Seems a name resolving problem. If you use Linux/MacOS, add the hostname and its IP address in hosts file:
# echo "123.123.123.123 dbxxxxxxxxx.db.1and1.com" >> /etc/hosts
You must replace this example IP for the real one.

MySQL Connection String Using PHP

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.

Categories