Google app engine 谷歌应用程序引擎Flexible can';t连接到Google云SQL MySQL

Google app engine 谷歌应用程序引擎Flexible can';t连接到Google云SQL MySQL,google-app-engine,google-cloud-sql,symfony-3.3,google-app-engine-php,symfony3.x,Google App Engine,Google Cloud Sql,Symfony 3.3,Google App Engine Php,Symfony3.x,我无法让我在Google App Engine Flexible上的Symfony 3项目连接到Google Cloud SQL(MySQL,2.Generation) 从这些例子开始 我在europe-west3创建了一个Google应用程序引擎和一个Google云SQL(MySQL,2.Generation)。 我在GAE上测试了这些示例,它们都运行良好 然后我继续从零开始创建了一个新的非常简单的Symfony 3.3项目。 创建之后(只有欢迎屏幕和“您的应用程序现在已经准备好了。您可以

我无法让我在Google App Engine Flexible上的Symfony 3项目连接到Google Cloud SQL(MySQL,2.Generation)

从这些例子开始

我在europe-west3创建了一个Google应用程序引擎和一个Google云SQL(MySQL,2.Generation)。 我在GAE上测试了这些示例,它们都运行良好

然后我继续从零开始创建了一个新的非常简单的Symfony 3.3项目。 创建之后(只有欢迎屏幕和“您的应用程序现在已经准备好了。您可以在:/app/”开始工作),我将其部署到我的GAEflex中,并且工作正常

之后,我添加了一个简单的实体和一个额外的控制器。 当启动Googles cloud\u sql\u代理和Symfony内置Web服务器“PHPBIN/console服务器:运行”时,这应该可以正常工作。 它在云SQL中读写,一切都很简单

但是,无论我尝试了什么,我总是在composer.json中的“symfony scripts”“post-install cmd”命令的其中一个(或另一个,取决于我的实验状态)上得到“拒绝连接”

“$gcloud测试版应用程序部署”输出(节选)

parameters.yml(节选)

config.yml(节选)

composer.json(节选)

app.yml(完整)

请记住,我只添加或更改了示例和文档建议我添加或更改的行

我做错了什么? 这两个例子都很好用,一个Symfony项目通过一个运行的cloud\u sql\u代理连接到数据库也很好用,当我试图从一个GAEflex中连接到CloudSQL时,我没有连接

有人能发现我可能犯的新秀错误吗? 有没有人遇到过这个问题,也许我忘记了GAE或CloudSQL的一个或另一个设置? 有人能告诉我一个使用GAEFlex和CloudSQL的正在运行的Symfony3/Doctrine项目的存储库吗

我被卡住了,因为我找不到任何关于如何运行这个相当明显的组合的最新文档。 非常感谢您的帮助

干杯/卡斯滕我找到了。 我读了这篇文章,得到了两条有趣的信息

  • PHP应用程序引擎Flex不再运行
    post deploy cmd
  • 只需使用
    post-install cmd
    作为替代品,除非您需要DB连接
  • 因此,在部署期间,根本没有可用的数据库连接/套接字! 这就是为什么谷歌推出了(非标准的)
    post-deploy cmd
    ,不幸的是,它似乎引发了一些其他问题,所以他们再次删除了它。糟糕透了

    实际上,到目前为止,在post-install cmd中不能使用任何利用数据库的东西

    在上面的例子中,我只是改变了

    composer.json(节选)

    一切都很好

    我不确定
    installAssets
    的内在功能,当我将其移动到pre-install时是否仍能达到最初的预期效果,但是,它适用于一个非常简单的示例应用程序。。。 在接下来的几天里,我将把这个应用程序带到我更复杂的应用程序中,看看我是否能让它正常工作

    进一步的讨论很可能在会议上结束


    大家干杯

    我不熟悉Symfony,但是如果从config.yml中删除主机/端口行,会发生什么?错误消息(“连接被拒绝”)表明它正在尝试通过TCP连接,而不是使用UNIX套接字。关于“连接被拒绝”提示TCP,您是对的,但是,不,然后它说“SQLSTATE[HY000][2002]没有这样的文件或目录”。我有没有提到我已经思考了好几天了?在我找不到一个例子后,除了在键盘上转动我的头之外,我愿意尝试我能想到的一切。这就是为什么我问是否有人可以肯定地指出我的错误或一个有效的项目。你能再次检查一下你是否启用了云SQL API吗?请参见此处“开始前”下的第2点:瓦迪姆。
    ...
    Step #1: Install PHP extensions...
    Step #1: Running composer...
    Step #1: Loading composer repositories with package information
    ...
    Step #1:     [Doctrine\DBAL\Exception\ConnectionException]
    Step #1:     An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
    Step #1:
    Step #1:
    Step #1:     [Doctrine\DBAL\Driver\PDOException]
    Step #1:     SQLSTATE[HY000] [2002] Connection refused
    Step #1:
    Step #1:
    Step #1:     [PDOException]
    Step #1:     SQLSTATE[HY000] [2002] Connection refused
    ...
    
    parameters:
        database_host: 127.0.0.1
        database_port: 3306
        database_name: gae-test-project
        database_user: root
        database_password: secretpassword
    
    doctrine:
        dbal:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            unix_socket: '/cloudsql/restof:europe-west3:connectionname'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
            charset: utf8mb4
            default_table_options:
                charset: utf8mb4
                collate: utf8mb4_unicode_ci
    
    "require": {
        "php": "^7.1",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "incenteev/composer-parameter-handler": "^2.0",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "sensio/generator-bundle": "^3.0",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.3.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-install-cmd": [
            "chmod -R ug+w $APP_DIR/var",
            "@symfony-scripts"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },
    
    service: default
    runtime: php
    env: flex
    
    runtime_config:
      document_root: web
    
    env_variables:
      SYMFONY_ENV: prod
      MYSQL_USER: root
      MYSQL_PASSWORD: secretpassword
      MYSQL_DSN: mysql:unix_socket=/cloudsql/restof:europe-west3:connectionname;dbname=gae-test-project
      WHITELIST_FUNCTIONS: libxml_disable_entity_loader
    
    #[START cloudsql_settings]
    # Use the connection name obtained when configuring your Cloud SQL instance.
    beta_settings:
        cloud_sql_instances: "restof:europe-west3:connectionname"
    #[END cloudsql_settings]
    
    "scripts": {
        "symfony-scripts": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "pre-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "post-install-cmd": [
            "chmod -R ug+w $APP_DIR/var",
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "@symfony-scripts"
        ]
    },