迁移到 IBM Bluemix 期间 ClearDB 连接出错

Error with ClearDB connection during migration to IBM Bluemix

我正尝试在我的 PHP 应用程序上使用 ClearDB 服务,该应用程序位于 IBM Bluemix 上托管的 Symfony 3 上。我有 成功将 cleardb 服务与应用程序链接起来,并获得了所有从 Bluemix 仪表板收集的凭据。

但是在应用程序上传(cf push)期间发生错误:

驱动程序发生异常:

SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password:
YES) 
[Doctrine\DBAL\Driver\PDOException] 

SQLSTATE[HY000] [1045] Access denied for user
'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)

我已经联系了 ClearDB 支持,他们确认我的帐户已启用并拥有所有权限。

我正在使用 https://github.com/cloudfoundry/php-buildpack

这是完整的错误日志:

2016-06-20T22:58:00.69+0200 [API/0]      OUT Updated app with guid 3ddcce14-6aa2-421c-bb8b-1b29b03265be ({"name"=>"qtogo-admin", "memory"=>128, "buildpack"=>"https://github.com/cloudfoundry/php-buildpack", "environment_json"=>"PRIVATE DATA HIDDEN"})
2016-06-20T22:58:40.46+0200 [API/2]      OUT Updated app with guid 3ddcce14-6aa2-421c-bb8b-1b29b03265be ({"state"=>"STOPPED"})
2016-06-20T22:58:42.78+0200 [DEA/191]    OUT Got staging request for app with id 3ddcce14-6aa2-421c-bb8b-1b29b03265be
2016-06-20T22:58:48.19+0200 [API/1]      OUT Updated app with guid 3ddcce14-6aa2-421c-bb8b-1b29b03265be ({"state"=>"STARTED"})
2016-06-20T22:58:49.56+0200 [STG/191]    OUT -----> Downloaded app package (43M)
2016-06-20T22:58:50.17+0200 [STG/0]      ERR     Cloning into '/tmp/buildpacks/php-buildpack'...
2016-06-20T22:58:59.13+0200 [STG/0]      OUT     Submodule 'compile-extensions' (https://github.com/cloudfoundry/compile-extensions) registered for path 'compile-extensions'
2016-06-20T22:58:59.20+0200 [STG/0]      ERR Cloning into 'compile-extensions'...
2016-06-20T22:59:01.18+0200 [STG/0]      OUT Submodule path 'compile-extensions': checked out '4a0e48afc46c1d467b7c75a8ae5e6f3a044d3d64'
2016-06-20T22:59:01.51+0200 [STG/0]      OUT -------> Buildpack version 4.3.14
2016-06-20T22:59:01.59+0200 [STG/0]      OUT Installing HTTPD
2016-06-20T22:59:05.22+0200 [STG/0]      OUT Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/httpd/httpd-2.4.20-linux-x64.tgz] to [/tmp]
2016-06-20T22:59:05.50+0200 [STG/0]      OUT WARNING: A version of PHP has been specified in both `composer.json` and `./bp-config/options.json`.
2016-06-20T22:59:05.50+0200 [STG/0]      OUT WARNING: The version defined in `composer.json` will be used.
2016-06-20T22:59:05.50+0200 [STG/0]      OUT Installing PHP
2016-06-20T22:59:05.50+0200 [STG/0]      OUT PHP 5.5.36
2016-06-20T22:59:30.02+0200 [STG/0]      OUT Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/php/php-5.5.36-linux-x64-1464282808.tgz] to [/tmp]
2016-06-20T22:59:41.48+0200 [STG/0]      OUT Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/php/php-5.5.36-linux-x64-1464282808.tgz] to [/tmp]
2016-06-20T22:59:45.01+0200 [STG/0]      OUT Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/php/binaries/trusty/composer/1.1.2/composer.phar] to [/tmp]
2016-06-20T22:59:45.01+0200 [STG/0]      OUT PROTIP: Include a `composer.lock` file with your application! This will make sure the exact same version of dependencies are used when you deploy to CloudFoundry.
2016-06-20T22:59:45.03+0200 [STG/0]      ERR   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2016-06-20T22:59:45.04+0200 [STG/0]      ERR                                  Dload  Upload   Total   Spent    Left  Speed
2016-06-20T22:59:45.45+0200 [STG/0]      ERR 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   283  100   283    0     0    674      0 --:--:-- --:--:-- --:--:--   675
2016-06-20T22:59:45.68+0200 [STG/0]      ERR Loading composer repositories with package information
2016-06-20T22:59:45.82+0200 [STG/0]      ERR Updating dependencies
2016-06-20T23:00:26.42+0200 [STG/0]      ERR   - Installing doctrine/cache (v1.6.0)
2016-06-20T23:00:26.42+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:29.32+0200 [STG/0]      ERR   - Installing doctrine/inflector (v1.1.0)
2016-06-20T23:00:29.32+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:31.37+0200 [STG/0]      ERR   - Installing symfony/polyfill-util (v1.2.0)
2016-06-20T23:00:31.37+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:33.46+0200 [STG/0]      ERR   - Installing paragonie/random_compat (v2.0.2)
2016-06-20T23:00:33.46+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:35.52+0200 [STG/0]      ERR   - Installing symfony/polyfill-php70 (v1.2.0)
2016-06-20T23:00:35.52+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:37.45+0200 [STG/0]      ERR   - Installing symfony/polyfill-php56 (v1.2.0)
2016-06-20T23:00:37.45+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:39.55+0200 [STG/0]      ERR   - Installing symfony/polyfill-mbstring (v1.2.0)
2016-06-20T23:00:39.55+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:41.59+0200 [STG/0]      ERR   - Installing symfony/symfony (v3.1.1)
2016-06-20T23:00:41.59+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:47.72+0200 [STG/0]      ERR   - Installing symfony/polyfill-intl-icu (v1.2.0)
2016-06-20T23:00:47.72+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:49.68+0200 [STG/0]      ERR   - Installing psr/log (1.0.0)
2016-06-20T23:00:49.68+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:51.75+0200 [STG/0]      ERR   - Installing psr/cache (1.0.0)
2016-06-20T23:00:51.75+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:53.96+0200 [STG/0]      ERR   - Installing twig/twig (v1.24.1)
2016-06-20T23:00:53.96+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:56.79+0200 [STG/0]      ERR   - Installing doctrine/lexer (v1.0.1)
2016-06-20T23:00:56.79+0200 [STG/0]      ERR     Downloading
2016-06-20T23:00:58.75+0200 [STG/0]      ERR   - Installing doctrine/annotations (v1.2.7)
2016-06-20T23:00:58.75+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:00.76+0200 [STG/0]      ERR   - Installing doctrine/collections (v1.3.0)
2016-06-20T23:01:00.76+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:02.94+0200 [STG/0]      ERR   - Installing doctrine/common (v2.6.1)
2016-06-20T23:01:02.94+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:05.41+0200 [STG/0]      ERR   - Installing doctrine/doctrine-cache-bundle (1.3.0)
2016-06-20T23:01:05.41+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:07.63+0200 [STG/0]      ERR   - Installing jdorn/sql-formatter (v1.2.17)
2016-06-20T23:01:07.63+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:09.79+0200 [STG/0]      ERR   - Installing doctrine/dbal (v2.5.4)
2016-06-20T23:01:09.79+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:12.26+0200 [STG/0]      ERR   - Installing doctrine/doctrine-bundle (1.6.3)
2016-06-20T23:01:12.26+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:14.70+0200 [STG/0]      ERR   - Installing doctrine/instantiator (1.0.5)
2016-06-20T23:01:14.70+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:16.77+0200 [STG/0]      ERR   - Installing doctrine/orm (v2.5.4)
2016-06-20T23:01:16.77+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:19.39+0200 [STG/0]      ERR   - Installing th3mouk/doctrine-table-prefix-bundle (1.0.1)
2016-06-20T23:01:19.39+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:21.30+0200 [STG/0]      ERR   - Installing willdurand/jsonp-callback-validator (v1.1.0)
2016-06-20T23:01:21.30+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:23.18+0200 [STG/0]      ERR   - Installing friendsofsymfony/jsrouting-bundle (1.6.0)
2016-06-20T23:01:23.18+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:25.32+0200 [STG/0]      ERR   - Installing phpoption/phpoption (1.5.0)
2016-06-20T23:01:25.32+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:27.22+0200 [STG/0]      ERR   - Installing phpcollection/phpcollection (0.4.0)
2016-06-20T23:01:27.22+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:29.27+0200 [STG/0]      ERR   - Installing jms/parser-lib (1.0.0)
2016-06-20T23:01:29.27+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:31.18+0200 [STG/0]      ERR   - Installing jms/metadata (1.5.1)
2016-06-20T23:01:31.18+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:33.31+0200 [STG/0]      ERR   - Installing jms/serializer (1.1.0)
2016-06-20T23:01:33.31+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:35.89+0200 [STG/0]      ERR   - Installing jms/serializer-bundle (1.1.0)
2016-06-20T23:01:35.89+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:38.22+0200 [STG/0]      ERR   - Installing kriswallsmith/buzz (v0.15)
2016-06-20T23:01:38.22+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:40.36+0200 [STG/0]      ERR   - Installing richsage/rms-push-notifications-bundle (dev-master 324b294)
2016-06-20T23:01:40.36+0200 [STG/0]      ERR     Cloning 324b29431ad58a006f53891cb103fad65c23d948
2016-06-20T23:01:44.96+0200 [STG/0]      ERR   - Installing friendsofsymfony/user-bundle (dev-master d1fccc6)
2016-06-20T23:01:44.96+0200 [STG/0]      ERR     Cloning d1fccc6335b74beca94525551cacc06b256ed261
2016-06-20T23:01:52.54+0200 [STG/0]      ERR   - Installing nelmio/cors-bundle (1.4.1)
2016-06-20T23:01:52.54+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:54.47+0200 [STG/0]      ERR   - Installing incenteev/composer-parameter-handler (v2.1.2)
2016-06-20T23:01:54.47+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:56.56+0200 [STG/0]      ERR   - Installing swiftmailer/swiftmailer (v5.4.2)
2016-06-20T23:01:56.56+0200 [STG/0]      ERR     Downloading
2016-06-20T23:01:59.03+0200 [STG/0]      ERR   - Installing symfony/swiftmailer-bundle (v2.3.11)
2016-06-20T23:01:59.03+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:01.22+0200 [STG/0]      ERR   - Installing monolog/monolog (1.19.0)
2016-06-20T23:02:01.22+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:03.65+0200 [STG/0]      ERR   - Installing symfony/monolog-bundle (2.11.1)
2016-06-20T23:02:03.65+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:05.83+0200 [STG/0]      ERR   - Installing sensiolabs/security-checker (v3.0.2)
2016-06-20T23:02:05.84+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:07.88+0200 [STG/0]      ERR   - Installing sensio/distribution-bundle (v5.0.6)
2016-06-20T23:02:07.88+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:09.95+0200 [STG/0]      ERR   - Installing sensio/framework-extra-bundle (v3.0.16)
2016-06-20T23:02:09.96+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:12.08+0200 [STG/0]      ERR   - Installing zendframework/zend-eventmanager (3.0.1)
2016-06-20T23:02:12.08+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:14.43+0200 [STG/0]      ERR   - Installing zendframework/zend-code (2.6.3)
2016-06-20T23:02:14.43+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:16.67+0200 [STG/0]      ERR   - Installing ocramius/proxy-manager (1.0.2)
2016-06-20T23:02:19.20+0200 [STG/0]      ERR   - Installing doctrine/migrations (1.4.1)
2016-06-20T23:02:19.20+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:21.39+0200 [STG/0]      ERR   - Installing doctrine/doctrine-migrations-bundle (1.1.1)
2016-06-20T23:02:21.39+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:23.42+0200 [STG/0]      ERR   - Installing kriswallsmith/assetic (v1.3.2)
2016-06-20T23:02:23.42+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:25.60+0200 [STG/0]      ERR   - Installing symfony/assetic-bundle (v2.8.0)
2016-06-20T23:02:25.60+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:27.78+0200 [STG/0]      ERR   - Installing vich/uploader-bundle (1.1.0)
2016-06-20T23:02:27.78+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:29.83+0200 [STG/0]      ERR   - Installing willdurand/negotiation (1.5.0)
2016-06-20T23:02:29.83+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:31.91+0200 [STG/0]      ERR   - Installing friendsofsymfony/rest-bundle (1.7.7)
2016-06-20T23:02:31.91+0200 [STG/0]      ERR     Downloading
2016-06-20T23:02:37.32+0200 [STG/0]      ERR Writing lock file
2016-06-20T23:02:37.32+0200 [STG/0]      ERR Generating autoload files
2016-06-20T23:02:37.36+0200 [STG/0]      ERR > Incenteev\ParameterHandler\ScriptHandler::buildParameters
2016-06-20T23:02:37.37+0200 [STG/0]      OUT Creating the "app/config/parameters.yml" file
2016-06-20T23:02:37.38+0200 [STG/0]      ERR > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
2016-06-20T23:02:37.91+0200 [STG/0]      ERR > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
2016-06-20T23:02:39.45+0200 [STG/0]      OUT   [Doctrine\DBAL\Exception\ConnectionException]                                                                                                        
2016-06-20T23:02:39.45+0200 [STG/0]      OUT   An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)  
2016-06-20T23:02:39.49+0200 [STG/0]      OUT   [Doctrine\DBAL\Driver\PDOException]                                                                                  
2016-06-20T23:02:39.49+0200 [STG/0]      OUT   SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)  
2016-06-20T23:02:39.51+0200 [STG/0]      OUT   [PDOException]                                                                                                       
2016-06-20T23:02:39.51+0200 [STG/0]      OUT   SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)  
2016-06-20T23:02:39.57+0200 [STG/0]      ERR Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
2016-06-20T23:02:40.03+0200 [STG/0]      ERR   [RuntimeException]                                                                                                                                       
2016-06-20T23:02:40.03+0200 [STG/0]      ERR   An error occurred when executing the "'cache:clear --no-warmup'" command:                                                                                
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     [Doctrine\DBAL\Exception\ConnectionException]                                                                                                          
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)    
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     [Doctrine\DBAL\Driver\PDOException]                                                                                                                    
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)                                    
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     [PDOException]                                                                                                                                         
2016-06-20T23:02:40.03+0200 [STG/0]      ERR     SQLSTATE[HY000] [1045] Access denied for user 'bf655aa76ba65b'@'ip-10-139-25-93.ec2.internal' (using password: YES)                                    
2016-06-20T23:02:40.03+0200 [STG/0]      ERR   .                                                                                                                                                        
2016-06-20T23:02:40.03+0200 [STG/0]      ERR install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...
2016-06-20T23:02:40.74+0200 [STG/0]      OUT -----> Composer command failed
2016-06-20T23:02:40.75+0200 [STG/0]      ERR Traceback (most recent call last):
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/scripts/compile.py", line 50, in <module>
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     .from_build_pack('lib/additional_commands')
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/builder.py", line 208, in extensions
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     process_extension(path, ctx, 'compile', process, args=[self])
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/utils.py", line 69, in process_extension
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     success(getattr(extn, to_call)(*args))
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 412, in compile
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     return composer.compile(install)
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/lib/extension_helpers.py", line 154, in compile
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     self._compile(install)
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 179, in _compile
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     self.run()
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 314, in run
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     *self._ctx['COMPOSER_INSTALL_OPTIONS'])
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/extensions/composer/extension.py", line 358, in run
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     shell=True)
2016-06-20T23:02:40.75+0200 [STG/0]      ERR   File "/tmp/buildpacks/php-buildpack/lib/build_pack_utils/runner.py", line 109, in stream_output
2016-06-20T23:02:40.75+0200 [STG/0]      ERR     raise CalledProcessError(retcode, cmd)
2016-06-20T23:02:40.75+0200 [STG/0]      ERR build_pack_utils.runner.CalledProcessError: Command '<open file '<fdopen>', mode 'w' at 0x7f875028b8a0>' returned non-zero exit status 1
2016-06-20T23:02:40.77+0200 [STG/0]      OUT Staging failed: Buildpack compilation step failed
2016-06-20T23:02:41.03+0200 [API/1]      ERR encountered error: App staging failed in the buildpack compile phase

我在日志中看到了这个:

Cr[STG/0]      OUT Creating the "app/config/parameters.yml" file

作曲家所做的是在作曲家更新期间使用 app/config/parameters.yml.dist 生成新的 parameters.yml 文件。所以您想进入 parameters.yml.dist 并设置您计划使用的所有正确值(即 database_password)。

在 Bluemix 的大力支持下,我终于弄明白了。您不能将凭据硬编码为 parameters.yml.dist,而是必须动态加载它。

我的解决方案是使用从 vcap 变量加载的参数创建自定义文件 bluemix.php,如下所示:

<?php

// load default parameters when working on local environment
if( empty($vcap_services = json_decode($_ENV["VCAP_SERVICES" ]) ) ) {
    $container->setParameter('database_host', '127.0.0.1');
    // ...
}

// load credentials from cleardb service
else {
    $db = $vcap_services->{'cleardb'}[0]->credentials;
    $container->setParameter('database_host', $db->hostname);
    $container->setParameter('database_port', $db->port);
    $container->setParameter('database_name', $db->name);
    $container->setParameter('database_user', $db->username);
    $container->setParameter('database_password', $db->password);
}

// common parameters
$container->setParameter('mailer_transport', 'smtp');
// ...

然后将您的资源加载到 config.yml 或 config_prod.yml,如下所示:

imports:
- { resource: bluemix.php }
# ...