嗨,我正在使用谷歌应用程序引擎与云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。我错过了完成配置的事情吗?
这可能会提供一个有用的例子:https://gae-php-tips.appspot.com/2013/10/22/getting-started-with-laravel-on-php-for-app-engine/。
如该帖子中所述,您可以在app.yaml中定义env变量,然后修改database.php文件以访问它们。看起来您可能缺少app.yaml部分的设置。在应用程序引擎项目(包括在开发服务器上本地运行)的上下文中,将设置和访问这些变量。
我试图在App引擎上部署我的应用程序时遇到了类似的困难。我将与您分享我如何解决它。
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize",
"chmod -R 755 bootstrap\/cache"
]
runtime: php
env: flex
runtime_config:
document_root: public
env_variables:
# Put production environment variables here.
APP_ENV: production
APP_LOG: errorlog
APP_KEY: APP_KEY (DO NOT USE QUOTES)
CACHE_DRIVER: database
SESSION_DRIVER: database
## Set these environment variables according to your CloudSQL configuration.
DB_HOST: localhost
DB_PORT: 3306
DB_CONNECTION: mysql
DB_DATABASE: DATABASE_NAME (DO NOT USE QUOTES)
DB_USERNAME: USERNAME (DO NOT USE QUOTES)
DB_PASSWORD: PASSWORD (DO NOT USE QUOTES)
DB_SOCKET: /cloudsql/YOUR_INSTANCE_CONNECTION_NAME (DO NOT USE QUOTES)
QUEUE_DRIVER: database
beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
# e.g. "project:region:cloudsql-instance"
cloud_sql_instances: "YOUR_INSTANCE_CONNECTION_NAME"