在进行任何API调用时,有时我的域(example.test.org)会向我显示错误.
"{"error":{"code":500,"message":"Undefined index: DB_HOST","file":"\/var\/www\/app\/config\/production\/database.php","line":7}}".
但是使用我本地机器的公共IP它正在工作.有什么理由会从一个域而不是另一个域返回错误?API在Laravel 4.2上运行.
database.php的输出是
'pgsql', 'connections' => array( 'pgsql' => array( 'host' => $_ENV['DB_HOST'], 'port' => $_ENV['DB_PORT'], 'database' => $_ENV['DB_NAME'], 'username' => $_ENV['DB_USER'], 'password' => $_ENV['DB_PASS'], ), ), );
这些值来自/var/www/.env.php,看起来像
return array( 'DB_HOST' => 'my-app.cvrrctfasmvk.us-east-1.rds.amazonaws.com', 'DB_PORT' => '*****', 'DB_NAME' => '**************', 'DB_USER' => '**********', 'DB_PASS' => '***********', 'SMTP_HOST' => '*******************', 'SMTP_USER' => '***********************', 'SMTP_PASS' => '********************************', 'AWS_KEY' => '****************************', 'AWS_SECRET' => '*******************', 'AWS_QUEUE' => '*****************************************', 'FB_APP_ID' => '*****************', 'FB_APP_SECRET' => '*********************' );
顺便说一下,DB Host文件看起来像这样.当然,可识别的值被改为x
'my-app-.xxxxxx.us-east-1.xxx.amazonaws.com', 'DB_PORT' => 'xxxx', 'DB_NAME' => 'xxxx_app_xxx_db', 'DB_USER' => 'xxxx', 'DB_PASS' => 'xxxx', 'SMTP_HOST' => 'email-xxx.xxxx.amazonaws.com', 'SMTP_USER' => 'xxxxxxx', 'SMTP_PASS' => 'xxxx', 'AWS_KEY' => 'xxx', 'AWS_SECRET' => 'xxxx', 'AWS_QUEUE' => 'https://sqs.xxxxx.amazonaws.com/xxxx', 'FB_APP_ID' => 'xxxxx', 'FB_APP_SECRET' => 'xxxx' );
看起来它在阅读/var/www/.env.php文件时遇到了问题.由于数组中的第一项是返回错误.