I have changed the Symfony demo application configuration from SQLite to MySQL. Locally it works fine for me, but if I try to deploy it in the Google App Engine Standard environment it doesn't work.
It is not clear to me how I should put the connection string if the database is in Google Cloud SQL. Currently the project's .env
file has this:
DATABASE_URL="mysql://dbname=THEDATABASENAME;unix_socket=PROJECTNAME:ZONE:INSTANCENAME"
I'm not sure if it's correct, or if something is missing, or if I need to configure something else in Symfony or in the Google Cloud Console.
When I deploy and browse to the site, I'm having Error 500.
The error log shows this:
2022-11-02 14:41:00 default[20221102t151407] "GET / HTTP/1.1" 302
2022-11-02 14:41:01 default[20221102t151407] nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3
2022-11-02 14:41:03 default[20221102t151407] "GET /es HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/app.c5bd2611.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/runtime.725dd7e0.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/755.5a8586e9.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/95.1ed6b32f.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/app.17316efd.css HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/fonts/fa-solid-900.1551f4f6.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/fonts/fa-regular-400.7a333762.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/95.22c66ae4.css HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/823.168b723b.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/31.46aa6824.js HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/fonts/lato-bold.21b3848a.woff2 HTTP/1.1" 200
2022-11-02 14:41:03 default[20221102t151407] "GET /build/fonts/lato-normal.75614cfc.woff2 HTTP/1.1" 200
2022-11-02 14:41:08 default[20221102t151407] "GET /es/blog/ HTTP/1.1" 500
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Matched route \"blog_index\".","context":{"route":"blog_index","route_parameters":{"_route":"blog_index","page":"1","_format":"html","_controller":"App\\Controller\\BlogController::index","_locale":"es"},"request_uri":"https://testMYPROJECT.uc.r.appspot.com/es/blog/","method":"GET"},"level":200,"level_name":"INFO","channel":"request","datetime":"2022-11-02T14:41:08.499913 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Checking for authenticator support.","context":{"firewall_name":"main","authenticators":1},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500353 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Checking support on authenticator.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500361 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Authenticator does not support the request.","context":{"firewall_name":"main","authenticator":"Symfony\\Component\\Security\\Http\\Authenticator\\FormLoginAuthenticator"},"level":100,"level_name":"DEBUG","channel":"security","datetime":"2022-11-02T14:41:08.500367 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"App\Controller\BlogController\" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"App\Controller\BlogController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:08.528050 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"ea12799f***********\" of type Doctrine\\ORM\\Query\\ParserResult: fopen(/workspace/var/cache/prod/pools/system/16ctGUzn1Q/774b86986a15): Failed to open stream: No such file or directory","context":{"key":"ea12799f**********","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/16ctGU**********): Failed to open stream: No such file or directory","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.092063 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Uncaught PHP Exception Doctrine\\DBAL\\Exception\\ConnectionException: \"An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused\" at /workspace/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 101","context":{"exception":{"class":"Doctrine\\DBAL\\Exception\\ConnectionException","message":"An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:101","previous":{"class":"Doctrine\\DBAL\\Driver\\PDO\\Exception","message":"SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28","previous":{"class":"PDOException","message":"SQLSTATE[HY000] [2002] Connection refused","code":2002,"file":"/workspace/vendor/doctrine/dbal/src/Driver/PDO/MySQL/Driver.php:28"}}}},"level":500,"level_name":"CRITICAL","chann"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "el":"request","datetime":"2022-11-02T14:41:09.173672 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"Symfony\Component\HttpKernel\Controller\ErrorController\" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony\Component\HttpKernel\Controller\ErrorController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.191792 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"Symfony\Component\HttpKernel\Controller\ErrorController#__invoke\" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony\Component\HttpKernel\Controller\ErrorController#__invoke","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.192185 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"Symfony\Bundle\FrameworkBundle\Controller\TemplateController\" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony\Bundle\FrameworkBundle\Controller\TemplateController","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.700565 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] [02-Nov-2022 14:41:09] WARNING: [pool app] child 20 said into stderr: "{"message":"Failed to save key \"Symfony\Bundle\FrameworkBundle\Controller\TemplateController#templateAction\" of type array: fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","context":{"key":"Symfony\Bundle\FrameworkBundle\Controller\TemplateController#templateAction","exception":{"class":"ErrorException","message":"fopen(/workspace/var/cache/prod/pools/system/qGYD7CGfrN/d7b0f5b96ec8): Failed to open stream: Read-only file system","code":0,"file":"/workspace/vendor/symfony/cache/Traits/FilesystemCommonTrait.php:99"},"cache-adapter":"Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter"},"level":300,"level_name":"WARNING","channel":"cache","datetime":"2022-11-02T14:41:09.701047 00:00","extra":{}}"
2022-11-02 14:41:09 default[20221102t151407] "GET /build/fonts/fa-brands-400.d878b0a6.woff2 HTTP/1.1" 200
2022-11-02 14:41:09 default[20221102t151407] "GET /build/css/app.4aa95248.css HTTP/1.1" 404
CodePudding user response:
The Google App Engine (Standard) docs for connecting to Cloud SQL note that:
Once correctly configured, you can connect your service to your Cloud SQL instance's Unix domain socket accessed on the environment's filesystem at the following path: /cloudsql/INSTANCE_CONNECTION_NAME
Your unix_socket
value above should be:
/cloudsql/project:region:instance-id
rather than just
project:region:instance-id
Also note that it should be the region, not the zone, i.e., northamerica-northeast1
rather than northamerica-northeast1-a
. When in doubt, you can verify the connection name either:
- on the overview page in the console for the target SQL instance
- by running
gcloud sql instances describe INSTANCE_NAME
Finally, you may also need to verify that:
- the service account for your App Engine service has the
Cloud SQL Client
role in the project hosting the SQL instance and the project hosting the App Engine service - the Cloud SQL Admin API (
sqladmin.googleapis.com
) is enabled on both the project hosting the SQL instance and the project hosting the App Engine service