Skip to content

Instantly share code, notes, and snippets.

@ellefsen

ellefsen/Procfile

Last active Apr 9, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.