title: Connecting PHP code on Compute Engine to Cloud SQL securely
body: <p>I'm trying to connect drupal cms running on a Compute Instance to Cloud SQL database but every combination I try fails. I can connect to Cloud SQl from another server but I'm not sure what path the MySQL connection takes from my instance to Cloud SQL but also want to configure as secure as possible connection to and from the db server</p>
  
  <p>Here is the configuration I have</p>
  
  <p><strong>Servers</strong></p>
  
  <ul>
  <li>Cloud SQL with external IP address assigned. Also authorized
  external IP address of compute instance &amp; Independent Server's IP
  address to connect.</li>
  <li>Compute Instance with external IP address running apache &amp; php successfully on the internet </li>
  <li>Trying to configure database connection from web browser as per step 4 of <a href="https://drupal.org/documentation/install/run-script" rel="nofollow">https://drupal.org/documentation/install/run-script</a> for drupal code running on compute instance</li>
  <li>Independent Server with internet accessible IP address </li>
  </ul>
  
  <p><strong>Users</strong></p>
  
  <ul>
  <li>SQL Root user password set and successfully used to connect from
  Independent Server using Workbench </li>
  <li>Db User from host % created to access drupal database and can successfully connect from Independent Server using workbench </li>
  <li>Same DB user wont connect from compute instance</li>
  </ul>
  
  <p><strong>Networking</strong></p>
  
  <ul>
  <li>Running ifconfig on compute instance only shows private Ip address</li>
  <li>I have opened 3306 on the Google firewall and the instance firewall</li>
  </ul>
  
  <p>My question is how do I get the compute instance to connect to cloud SQL by supplying the dbname, dbusername, dbuserpwd,host(IPAddress) so that it connects exactly like workbench but still have as restricted as possible?
  Does the issue lie with the configuration of the compute instance, the connection settings used supplied or cloud sql </p>