Skip to content

Instantly share code, notes, and snippets.

@GraxMonzo
Forked from ellefsen/Procfile
Created June 21, 2019 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GraxMonzo/d2d6bd1c328c4400ef2cc0f3feea4031 to your computer and use it in GitHub Desktop.
Save GraxMonzo/d2d6bd1c328c4400ef2cc0f3feea4031 to your computer and use it in GitHub Desktop.
Heroku with Google Cloud SQL and cloud_sql_proxy with PHP / Laravel
{
"name": "cloudsql-test",
"type": "project",
"license": "MIT",
"authors": [],
"require": {
"php": "~7.1.0",
"ext-gd": "*",
"ext-mcrypt": "*"
},
"scripts": {
"post-install-cmd": [
"bash ./proxy.sh"
]
}
}
{
"type": "service_account",
"project_id": "your-project",
}
<?php
// public/index.php
$dbname = 'testdb';
$dbuser = 'root';
$dbpass = 'pass?';
$dbhost = '127.0.0.1';
$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($link, $test_query);
$tblCnt = 0;
while ($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
//echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
web: (bash ./start.sh) & vendor/bin/heroku-php-nginx public/
#!/bin/bash
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.386
mv cloud_sql_proxy.linux.386 cloud_sql_proxy
chmod +x cloud_sql_proxy
// Start the proxy
./cloud_sql_proxy -instances=offmarket-staging:europe-west1:sql-test=tcp:3306 -credential_file=credentials.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment