【发布时间】:2014-08-01 17:13:46
【问题描述】:
您好,我正在使用带有云 sql 的谷歌应用引擎,但在部署基于 laravel 的应用时遇到问题。
一切都在我的本地计算机上运行,但在将数据库部署到云时我无法查询数据库。我收到以下错误。
InvalidArgumentException 未配置数据库 [phlingo_user]。
这就是我在 \app\config\database.php 中的内容
<?php
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
$u_array = array(
'driver' => 'mysql',
'unix_socket' => getenv('PRODUCTION_CLOUD_SQL_INSTANCE'),
'host' => '',
'database' => getenv('PRODUCTION_U_DB_NAME'),
'username' => getenv('PRODUCTION_DB_USERNAME'),
'password' => getenv('PRODUCTION_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
$c_array = array(
'driver' => 'mysql',
'unix_socket' => getenv('PRODUCTION_CLOUD_SQL_INSTANCE'),
'host' => '',
'database' => getenv('PRODUCTION_C_DB_NAME'),
'username' => getenv('PRODUCTION_DB_USERNAME'),
'password' => getenv('PRODUCTION_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
$p_array = array(
'driver' => 'mysql',
'unix_socket' => getenv('PRODUCTION_CLOUD_SQL_INSTANCE'),
'host' => '',
'database' => getenv('PRODUCTION_P_DB_NAME'),
'username' => getenv('PRODUCTION_DB_USERNAME'),
'password' => getenv('PRODUCTION_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
} else {
$u_array = array(
'driver' => 'mysql',
'host' => getenv('DEVELOPMENT_DB_HOST'),
'database' => getenv('DEVELOPMENT_U_DB_NAME'),
'username' => getenv('DEVELOPMENT_DB_USERNAME'),
'password' => getenv('DEVELOPMENT_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
$c_array = array(
'driver' => 'mysql',
'host' => getenv('DEVELOPMENT_DB_HOST'),
'database' => getenv('DEVELOPMENT_C_DB_NAME'),
'username' => getenv('DEVELOPMENT_DB_USERNAME'),
'password' => getenv('DEVELOPMENT_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
$p_array = array(
'driver' => 'mysql',
'host' => getenv('DEVELOPMENT_DB_HOST'),
'database' => getenv('DEVELOPMENT_P_DB_NAME'),
'username' => getenv('DEVELOPMENT_DB_USERNAME'),
'password' => getenv('DEVELOPMENT_DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
);
}
return array(
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => 'phlingo_user',
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
getenv('MYSQL_U') => $u_array,
getenv('MYSQL_C') => $c_array,
getenv('MYSQL_P') => $p_array,
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),
),
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
),
),
);
[phlingo_user] 指的是 $u_array。我是否缺少完成配置的内容?
【问题讨论】:
-
你的 app.yaml 中是否设置了这些环境变量?你可以在你的 laravel 配置文件中设置它们以使事情变得简单。连接到云 sql 实例时,Google 将为您锁定安全性。
-
不,他们不是。 Laravel 不会检测 app.yaml 中设置的环境变量。然而,它们位于根文件夹中名为 .env.php 的文件中,laravel 平台使用该文件
-
我还没有在 GAE 上为我的 laravel 应用程序尝试过 .env.php 的东西,所以不确定它们是否有效。我在配置中使用了一个 gae 文件夹,它工作正常。我现在将信息直接放入以进行测试。您需要做更多的工作来移动存储路径并让它们正常工作。
-
好吧,我做到了,它成功了,但我仍然想知道你如何能够在你的 laravel 应用程序中从你的 app.yaml 访问环境变量?我正在使用 laravel 4.2 你在配置文件夹中添加了什么?
-
@user3813559 你能给我发你的电子邮件吗,我想问你一些关于 Laravel 和 Google SQL 的事情
标签: php google-app-engine laravel laravel-4 google-cloud-sql