0

I'm a little bit frustrated with a problem I'm having in a system migration from AWS to GCE.

I've an ec-2 instance running on amazon web services, perfectly working and configured.

The problem is that google is offering a 100.000$ credit in a special plan for Startups, my company's CEO asks for a migration, so here I am.

I have all running and almost fully configured in a ubuntu 14.04 LTS instance, I said almost, because I can't achieve a simple task such as connect to a Mysql db :(, and I think I'm missing something in someplace and my mind gets offuscated, so I need your help.

First of all, I only having this problem on remote server, I've tested it like a hundred times in local, and of course in aws, where it is currently in production state, so I have no clue what or where exactly the problem is.

My GCE config:

OS: Ubuntu 14.04 LTS HHD: 30GB persistence ssd disk CPU : 2x RAM : 7,5 GB Zone: europe-west1-c Static Ip

So, I installed Lamp and phpmyadmin, all works like a charm. I disable root access from remote clients to Mysql db, configured php and apache modules.

The Web app is a Rest Api, based on PHP(Slim), that, like I just said, is now working on AWS.

When I call to and endpoint that doesn't need to retrieve any data from the db, it works well, the problem comes when the endpoint called try to access the db. In that case the request never respond, it keeps loading forever until I abort the request. It is kind of weird, because I can manipulate all the data through phpmyadmin, which access to the db the same way mysqli does.

If I checked the logs, nothing is printed on them. Only when I change the "locahost" host param, it prints a log saying: "No mysql db on XXX.XXX.XXX.XXX"(IP).

config.php File

define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'pass'); 
define('DB_HOST', 'localhost'); 
define('DB_NAME', 'db_name'); 

DbConnect.php

function connect() {
    include_once dirname(__FILE__) . '/Config.php';

    // Connecting to mysql database
    $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

    // Check for database connection error
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    /* change character set to utf8 */
    if (!$this->conn->set_charset("utf8")) {
        echo "Error loading character set utf8: " . $this->conn->error;
    } 

    // returing connection resource
    return $this->conn;
}

loops forever img

Expected Response img

Any help is welcome!

SvOzMaS
  • 1
  • 2

1 Answers1

0

Have you changed the bind-address parameter in the my.cnf MySQL config file? This has caught me a few times. MySQL by default in Ubuntu 14.04 will only listen on localhost and will ignore remote connections.

Also, check out the answer to this question and it might give you some help as well: Remote Connections Mysql Ubuntu - bind address failed

Community
  • 1
  • 1
ironpilot
  • 371
  • 3
  • 4
  • I forgot to mention it, but I've also tried to bind the ip. The result is similar: for localhost it keeps waiting for the never coming response, and if I try to access through the binded ip in the my.cnf file, same result, infinite response waiting. If I unbind the ip, it returns an exception, "No db in the address XXX.XXX........." Thanks anyway ;-) – SvOzMaS Apr 25 '16 at 15:27
  • Don't have a firewall blocking connections to your server do you, such as ufw or iptables? https://help.ubuntu.com/12.04/serverguide/firewall.html – ironpilot May 03 '16 at 16:38