Connecting Google Cloud SQL with Wordpress on Google Compute Engine - mysql

I've been running a successful Wordpress install on Google Compute Engine with Nginx, Php-fpm and Mysql.
I noticed you can also run Wordpress on App Engine with a Cloud SQL connection as mentioned here https://developers.google.com/appengine/articles/wordpress?hl=en
I want to use Wordpress on Compute Engine with the db running on Cloud SQL.
On AppEngine, you need to put the following lines in the wp-config.php file
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
define('DB_HOST', ':/cloudsql/YOUR_PROJECT_ID:wordpress_db_name');F
}else{
define('DB_HOST', 'localhost');
}
Is there a similar way to connect Wordpress on Compute Engine with Cloud SQL?

No. There is no need to connect to fancy socket names, you need to set up Wordpress as a usual MySQL client, just keep in mind that you need to pre-authorize Compute Engine instance to access your Cloud SQL instance.

Related

Connect with existing MySQL database (OVH) from Cloud Functions

I have an existing database hosted by OVH and managed by PhpMyAdmin.
On the other side, I also have a Firebase project where I use several Cloud Functions.
I would like write, in my existing OVH database, datas from my Firestore collections (thanks to Cloud Functions).
Is there a way to connect my Cloud Functions to an existing database ?
I did read than is possible to connect Cloud Functions to MySQL database with Cloud SQL but it seems only for new database created from Cloud Platform, which is not my usecase as my database is already created and hosted by OVH.
Thank you for your help!
Depending on the programming language you are using on Cloud Functions, PHP for example:
1. <?php
2. $myPDO = new PDO('pgsql:host=host;port=port;dbname=dbname', 'username', 'password');
3. ?>
From what I can tell on the documents, you have to make sure your database is public, not private. Here is the official documentation.
If you have any issues, try reaching out to OVH support.

Connecting Wordpress on Google Cloud Compute to CloudSQL DB

Ive tried and tried to get this to work to no avail.
I have WordPress running on Google Computer Engine, and I have my database on Google CloudSQL. Both are in the same project, and I have managed to connect to MySQL via the CloudSQL Proxy with:
./cloud_sql_proxy -dir=/cloudsql -instances=[CLOUDSQL INSTANCE CONNECTION] & mysql -u [CLOUDSQL USER] -S /cloudsql/[CLOUDSQL INSTANCE CONNECTION]
This brings up the mysql command where I can show my databases in that remote connection.
I am not sure if I need to put something in my wp-config.php file to pick up on the CloudSQL Database or what.
I already have the scope set to allow CloudSQL access, and I am able to actually connect from GCE over to the CloudSQL DB, but I am not sure how to get wordpress to access the DB.
I saw this here: Connecting Google Cloud SQL with Wordpress on Google Compute Engine But it didn't help me because I wasn't sure exactly what needed to be done.
I would be EXTREMELY greatful for any help.
Although you use Google Compute Engine instead of Google App Engine to host your WordPress, the configuration "wp-config.php" should be very similar to the code in https://github.com/GoogleCloudPlatform/appengine-php-wordpress-starter-project/blob/master/wp-config.php as described in http://googlecloudplatform.github.io/appengine-php-wordpress-starter-project/. You should set DB_HOST to ":/cloudsql/[CLOUDSQL INSTANCE CONNECTION]".

GCE instance to copy data from a different GCE MySQL database to Google CloudSQL

This may sound stupid and it is. But i'm wondering if it is possible to create a GCE instance that its sole purpose is to copy data from another GCE's MySQL database and copies all data to a Google Cloud SQL instance every few minutes and essentially updates the GCloud SQL.
Essentially i'm trying to get around how GAE can't connect to a GCE MySQL database but you can connect to a Google cloud SQL database.
I have tried "FEDERATED Tables" however Google Cloud SQL doesn't support that. So this is my last resort.
Thanks
Why do you need the GCE database at all? That is, why can't you just use a Cloud SQL database for all of your database needs?
You could try manually replaying the binary log to your Cloud SQL instance, ie:
Enable binary logging on your GCE MySQL instance.
Use mysqlbinlog to periodically extract the latest contents of the log as SQL statements. Use the positioning functions to make sure each run starts where the last finished.
Send the SQL outputted by mysqlbinlog to your Cloud SQL instance.

How to browse data in MySQL database on Amazon EC2?

I deployed my Rails app to Amazon EC2 server (Ubuntu), but I am thinking how to connect to MySQL database from terminal (SSL) and manually check data in database.
How to do that? I see in the database.yml file some credentials, but don't know how to connect/log in into MySQL on EC2 instance.
Thanks
There's no special magic involved here. An EC2 server is just... a server. This is not hosting like heroku or godaddy where your database is going to be hosted on a different db server.
Unless you explicitly setup a separate db server (which I don't think you did), you've got an entire virtual machine running Ubuntu, and the db server is most likely running on the same machine.
So you can ssh into the machine and just run the standard mysql client. Docs here: http://dev.mysql.com/doc/refman/5.6/en/mysql.html.
If you want to use some gui software such as sequel pro mentioned in one of the comments, you'll need to open up the ports in the aws console. Amazon closes all the ports by default. Do this to open up the port:
Open up the AWS control panel
Go to 'Security Groups'
Select the security group in the panel (you probably only have one).
Click the 'Inbound' tab.
Select Mysql from the dropdown list
Save the rule
This will open up port 3306 and enable you to use an external tool to see the server.
If you just want to call some sql to the database just to verify small amount of data, you can try doing these:
sql_statement = 'SELECT * FROM users'
ActiveRecord::Base.connection.execute(sql_statement).to_a

Configuring Play Application for MYSQL Database in Amazon EC2

I am trying to use a mysql database in my play 1.2.4 application hosted in Amazon EC2 .
For that, I configured application.conf file with the following snippet in my local environment.
db=mysql:root:password#databasename
and this works fine.
Same mysql server have been configured in my EC2 instance with same Database created .
What should be the configuration to use that DB in EC2 . After several trial and error methods , I am not able to make my Play application talk with the database .
Thanks in advance .
I would diagnose this problem with the following tests:
Can you reach your mysql server from the same machine you are running your application from?
When trying this, make sure that you use the same user and password as in your application.
Have a look at the mysql users table and check if the user is allowed to connect.
Is the mysql daemon bound to localhost or do you have to use the IP or external DNS name of the machine?
Try checking your firewall rules that the port for mysql is open from your application machine
Also check the EC2 Security group that the mysql port is open from your application machine.