0

I have created two servers on Linux and installed LAMP on both, one I called web and the other is called app.

I would like to save a log from the web server on the app server - but when I try to connect to the app server, I get timeout.

My code is:

$mysqli = mysqli_connect("66:66:666:66", "username", "pass", "DB");
    if (!$mysqli) {
        die("Connection failed: " . mysqli_connect_error());
    }

Where 66:66:666:66 is the ip to the app server.

I have in the app server under PhpMyAdmin added user privileges to a user with the name "username" and then the host is "%".

Have i forgotten something?

Edit: I have already tried to add port number 3306 to the connection.

Andreas Baran
  • 669
  • 1
  • 12
  • 27
  • did you open the firewall? most likely it's just dropping the packets, meaning your client never gets an icmp unreachable or whatever, so it just sits there until it times out the connection attempt. – Marc B Jul 27 '16 at 21:27
  • Have you checked the MySQL logs on the app server? On the app server is the mysql server listening on an external interface? – Jason K Jul 27 '16 at 21:28
  • @MarcB - do you know how to check if the firewall is open on port 3306 and if not open, how to open it on linux? – Andreas Baran Jul 27 '16 at 21:37
  • @JasonK - where can I find the MySQL log on my server? Sorry, but I don't understand what you mean about listening on an external interface? I have just created a simple Linux server and then installed LAMP by following this guide: docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html – Andreas Baran Jul 27 '16 at 21:38
  • Usually mysql is defaulted to localhost only. do a netstat -lnp|grep 3306 . If you see 127.0.0.1:3306 on the 4th collum it's only listening on localhost. Then you need to do a google search on how to change it for your distribution. If it's 0.0.0.0:3306 then it's listening on all ports. logs are usally in /var/log . – Jason K Jul 27 '16 at 21:46
  • @JasonK - when I run netstat -lnp|grep 3306, i get 0.0.0.0:3306 in third column and 0.0.0.0:* in fourth, so this should work. I have the logfile - is there something speciel that I should look for? – Andreas Baran Jul 27 '16 at 21:52
  • Should be listening on all interfaces then. Haven't used AWS. – Jason K Jul 27 '16 at 21:56
  • on AWS you should use RDS not host mysql on an instance –  Jul 27 '16 at 22:10

0 Answers0