0
votes

I am receiving an error when trying to load up my webpage

Failed to connect to MySQL: (2005) Unknown MySQL server host ':/cloudsql/testsite:europe-west1:testdatabase' (2)Error:

I have a Google Compute Engine VM set up with a LAMP stack (Apache/2.4.10 (Debian)/ Database client version: libmysql - 5.5.55 / PHP extension: mysqli)

I also have set up an instance on Google SQL with user credentials for aforementioned VM (i have set up both First Gen and Second Gen)

I can access both a local MySQL database on the VM as well as the Google SQL databases via phpAdmin installed locally

HOWEVER i appear to have an issue with the DB_HOST credentials in my config.php file when i run the script path = /var/www/html/includes/config.php

I get

usually for local MYSQL databases i use

// The MySQL credentials
$CONF['host'] = 'localhost';
$CONF['user'] = 'YOURDBUSER';
$CONF['pass'] = 'YOURDBPASS';
$CONF['name'] = 'YOURDBNAME';

Documentation (and github links) recommend path

:/cloudsql/project-id:region:sql-db-instance-name

which is what i have done (see above) - but i keep getting the error message.

Am i typing the host description incorrectly? Or have i missed a configuration step?

Thanks in advance

1

1 Answers

0
votes

It seems as if i have erred and that the credentials format i stated earlier are for Google App Engine

If you are on Google Compute Engine, you have two options:

  1. Connect to the public IP address of your Cloud SQL instance. This requires you whitelist your GCE instance on the ACL for the Cloud SQL instance.
  2. Use the Cloud SQL proxy. This is a extra daemon you run on your GCE instance that allows you to connect via TCP on localhost or a socket.