Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Cloud SQL #6

Closed
nickypeh opened this issue Feb 10, 2015 · 10 comments
Closed

Google Cloud SQL #6

nickypeh opened this issue Feb 10, 2015 · 10 comments

Comments

@nickypeh
Copy link

Hi,
I am getting this error at the first line:
production.ERROR: exception 'ErrorException' with message 'PDO::__construct(): MySQL server has gone away' in /base/data/home/apps/s~/1.382141415555912450/server/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47

I have configured the database.php in this format
$mysql_array = array(
'driver' => 'mysql',
'unix_socket' => getenv('PRODUCTION_CLOUD_SQL_INSTANCE'),
'host' => '',
'database' => getenv('PRODUCTION_DB_NAME'),
'username' => getenv('PRODUCTION_DB_USERNAME'),
'password' => getenv('PRODUCTION_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
);

I am following the guidelines from here
https://gae-php-tips.appspot.com/2013/10/22/getting-started-with-laravel-on-php-for-app-engine/

Replaced the <your_project>/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php file as in this gist: https://gist.github.com/gmergoil/5693102

Somehow this is showing error when I want to access it.

Please help to advise as I have tried to search across the web but it seems like it does not have any solution.

Thanks.

@shpasser
Copy link
Owner

The package still does not support MySQL, but I'm going to try adding the support in a couple of weeks.
Anyway in order to use MySQL on GAE you need to activate it either by paying for it or by evaluating it for 60 days.

@shpasser
Copy link
Owner

I just finished testing a simple app using Google Cloud SQL and it works just fine.

There was no need to update or replace the code of /vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php, the current version seems to be sufficient.

The configuration you sent looks ok, but since it is partial I would like to clarify on the actual values of the environment variables that are used:

PRODUCTION_CLOUD_SQL_INSTANCE: '/cloudsql/testApp:cloudSqlInstanceName'
PRODUCTION_DB_USERNAME: 'root'
PRODUCTION_DB_PASSWORD: ''
PRODUCTION_DB_NAME: 'laravel_db'

All these should work assuming:

  1. A Cloud SQL instance 'cloudSqlInstanceName' was created,
  2. 'testApp' was granted access to 'cloudSqlInstanceName',
  3. 'laravel_db' was created.
  4. last, but not least, do not use dashes - in database names, they appear as comments to the DB.

Please notice that the username is set to 'root' and the password is an empty string.

Also you might want to visit the link: https://cloud.google.com/appengine/docs/php/cloud-sql/

Please let me know if you managed to solve the problem.

@nickypeh
Copy link
Author

Hi,
It seems like I am still getting this error.

production.ERROR: exception 'ErrorException' with message 'PDO::__construct(): MySQL server has gone away' in /base/data/home/apps/s~/1.382162489786738070/server/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47

I deleted the instance and try again with new instance. But somehow it is not working as well.
I use back the original MySqlConnector.php version. Tried few rounds but still fail to connect to the database.
For the PRODUCTION_CLOUD_SQL_INSTANCE:
I copy the one listed on the Cloud SQL /cloudsql/:testingsql and I didnt set password for the root.

I am actually hitting dead end here. :(

Sorry to ask, but is it possible for you to share out the simple app you created? I am not sure whether I am missing some configuration.

Thanks.

@nickypeh
Copy link
Author

Hi,
Finally, I am able to connect to the Google Cloud SQL.

It was a silly mistake, I need to choose the same region of Google Cloud SQL with GAE as they can only provide correct authorisation.

However, when I tried to set password for root and it fails again with such error.
production.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)'

Any Idea to connect to the SQL with the password enable for root ?

This is because , I am using MySQL workbench to connect to the Google Cloud SQL and it would need root password in order to connect.

Please advise.

@shpasser
Copy link
Owner

Hi,

I use Sequel Pro and it works ok with the root password which I set via the GAE UI.

BTW you have to assign an IP address to the instance, unless you have IPv6 working, which I don't.

Another thing is access permissions for the IP address you are trying to connect from. You can just use "what is my ip" and add it for testing, of course you'll need another definition if your IP changes over time.

Hope this helps, if not contact me again.

Best,

Ron.

Sent from my iPhone

On Feb 11, 2015, at 6:38 PM, nickypeh notifications@github.com wrote:

Hi,
Finally, I am able to connect to the Google Cloud SQL.

It was a silly mistake, I need to choose the same region of Google Cloud SQL with GAE as they can only provide correct authorisation.

However, when I tried to set password for root and it fails again with such error.
production.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)'

Any Idea to connect to the SQL with the password enable for root ?

This is because , I am using MySQL workbench to connect to the Google Cloud SQL and it would need root password in order to connect.

Please advise.


Reply to this email directly or view it on GitHub.

@shpasser
Copy link
Owner

Any progress?

If the issue will remain inactive for 3 more days I'm going to close it.

@nickypeh
Copy link
Author

Hi,
Sorry for the late reply.
Everything is working fine as expected now :)
Using sequel pro and it can login without the root password as well.

Let say in the future, I am going to add password to the root account for the db, is there any workaround as of now, we are connecting without the root password.

Thanks.
Nicky

@shpasser
Copy link
Owner

Glad to hear that managed to solve the problem.

As for the password I realize it is only of use for remote connections, since while connecting from GAE
app the GAE should not allow a non-authorized application to connect to the DB.

I've managed to create an additional user with password and was able to connect to the DB
locally as well as from my GAE app. The tricky part here is to grant the user permissions for
connections from GAE as well as from Sequel Pro, take a look at the permissions granted to
'root' while connecting from hosts: '%', 'localhost', '127.0.0.1' (like it appears in 'root' user).

Best,

Ron.

@nickypeh
Copy link
Author

Hi Ron,
Thanks for the feedback. I think for the database its all working fine now :)
I think this could be closed now.
However, could you add some example for the mail part ?

Thanks.

Regards,
Nicky

@shpasser
Copy link
Owner

Hi Nicky,
Thanks for the feedback. I'm going to expand the automatic configuration generation to
include Cloud SQL support for Laravel 4 as well as for Laravel 5(in the Laravel 5 package).

As for Mail API, it should be out of the box, please see the following links:
http://laravel.com/docs/4.2/mail
http://culttt.com/2014/04/14/sending-email-laravel-4/

Please notice the limitations of the mail driver described in https://github.com/shpasser/GaeSupport/blob/master/README.md

The only not tested area is "Embedding Inline Attachments", but I do not think there should be
any problems.

If you encounter any problems please open a new issue regarding the Mail driver.

Best,

Ron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants