php - PCF - 不允许应用程序在 MySQL 中创建表

标签 php mysql cloud-foundry limesurvey pcf

我已成功将 Limesurvey.org 应用程序 (LAMP) 部署到 Pivotal Cloud。该应用程序基本上按预期工作,除了 MySQL 数据库不允许应用程序创建表。当激活给定的调查时,应用程序需要创建表来存储响应。

我已经在本地 (Linux) 安装了相同的应用程序,没有任何问题。另一个已将相同应用程序(不同版本)部署到 PCF 的团队建议我使用脚本(如下)捕获 VCAP_SERVICES 信息以连接数据库。然而,在“cf Push”之后,应用程序根本无法运行。这是一个 PHP 脚本。我在 Java 中似乎有类似的代码。

为什么我需要向 PCF 上的数据库提供 VCAP_SERVICES 信息?

也许如果我理解脚本想要做什么,我就能解决这个问题。

任何信息和/或提示将不胜感激。

class ApplicationConfiguration {
    private static function decrypt_password($base64_encrypted_password, $cf_instance_ip, $uuid) {
        $rsa_private_key = self::lookup_rsa_private_key ( $cf_instance_ip, $uuid );
        $encrypted_password = base64_decode ( $base64_encrypted_password );
        $decryption_result = openssl_private_decrypt ( $encrypted_password, $decrypted_password, $rsa_private_key );

        return $decrypted_password;
    }
    private static function lookup_rsa_private_key($cf_instance_ip, $uuid) {
        $private_key_lookup_url = 'http://' . $cf_instance_ip . ':1199/v1/cred/private_key/' . $uuid;

        // SSL certificate is currently self-signed, disable all validation
        $contextOptions = array (
                'ssl' => array (
                        'verify_peer' => false,
                        'verify_peer_name' => false 
                ) 
        );

        $rsa_private_key = file_get_contents ( $private_key_lookup_url, false, stream_context_create ( $contextOptions ) );

        return $rsa_private_key;
    }
    public static function getApplicationConfigurations() {
        $appConfigurations = array ();

        $dbDetails = getenv ( "VCAP_SERVICES" );

        $appConfigurations ["debug"] = getenv ( "DEBUG" );
        $appConfigurations ["debugsql"] = getenv ( "DEBUG_SQL" );

        if (getenv ( "TABLE_PREFIX" ) == NULL) {
            $appConfigurations ["tablePrefix"] = 'lime_';
        } else {
            $appConfigurations ["tablePrefix"] = getenv ( "TABLE_PREFIX" );
        }

        $dbDetailsObject = json_decode ( $dbDetails, true );

        $credentials = array ();

        if (array_key_exists ( "mariadb", $dbDetailsObject ) && $dbDetailsObject ["mariadb"] != NULL) {
            $credentials = $dbDetailsObject ['mariadb'] [0] ["credentials"];
            $appConfigurations ["connectionString"] = ('mysql:host=' . $credentials ["hostname"] . ';port=' . $credentials ["port"] . ';dbname=' . $credentials ["schema"] . ';');
        } else {
            $credentials = $dbDetailsObject ['p-mysql'] [0] ["credentials"];
            $appConfigurations ["connectionString"] = ('mysql:host=' . $credentials ["hostname"] . ';port=' . $credentials ["port"] . ';dbname=' . $credentials ["name"] . ';');
        }

        $appConfigurations ["userName"] = $credentials ["username"];
        $appConfigurations ["password"] = $credentials ["password"];

        if (array_key_exists ( "appGuid", $credentials ) && $credentials ["appGuid"] != NULL) {
            $cf_instance_ip = getenv ( "CF_INSTANCE_IP" );
            $appConfigurations ["password"] = self::decrypt_password ( $credentials ["password"], $cf_instance_ip, $credentials ["appGuid"] );
        }

        return $appConfigurations;
    }
}

最佳答案

这不是给db用户适当的权限的问题吗?

关于php - PCF - 不允许应用程序在 MySQL 中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49699653/

相关文章:

php - 与被识别为构造函数的类同名的小写方法

php - 32 位无符号整数 php

php - 高级搜索、PHP 和 MySQL

cloud-foundry - 如何查看 cf push 命令到 Cloud Foundry 的进度

cloud-foundry - 对 cf 命令的无效身份验证 token 响应

java - 在多个实例和单个数据库上的 Cloud Foundry Java 应用程序中提供数据一致性

javascript - 如何使用 get 方法来执行 PHP 的不同功能?

javascript - 在模式框中打开页面

mysql - 无法在 MySQL 上设置全局变量

php - 无限嵌套的分页