Laravel 5 .env.travis文件被忽略

时间:2015-02-15 18:14:19

标签: travis-ci laravel-5

我为Travis CI环境创建了一个新文件,看起来像这样

.env.travis

APP_ENV=travis 
APP_DEBUG=true 
APP_KEY=SomeRandomString

DB_HOST=127.0.0.1
DB_DATABASE=travis
DB_USERNAME=travis
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file

这个env文件似乎被忽略了。

我测试了使用此内容创建新的控制台类

public function fire()
{
    //
    echo env('APP_ENV') ."\n";
    echo "Database ". env('DB_DATABASE') ."\n";
    echo "Username ". env('DB_USERNAME') ."\n";
}

当我运行命令时,我得到了这个输出

➤ ./artisan env:database --env=travis
local
Database forge
Username forge

您知道为什么忽略环境文件吗?

2 个答案:

答案 0 :(得分:1)

我找到了一种方法来使用travis env文件。

这有点像黑客,但这样你就可以将.env文件与.env.travis文件分开了

只需运行复制命令,使用 .travis.yml 配置<中的 .env.travis 文件覆盖 .env 文件/ p>

before_script:
    - cp .env.travis .env

答案 1 :(得分:0)

If anyone like me is here to see a full config file to copy past it, here's a full travis config file that works well with Laravel 5.*

.travis.yml

language: php

php:
  - 5.5.9
  - 5.6
  - 7.0
  - hhvm

matrix:
    allow_failures:
        - php: hhvm

before_script:
- cp .env.travis .env
- mysql -e 'create database homestead;'
- composer self-update
- composer install --prefer-source --no-interaction --dev
- php artisan migrate
- php artisan db:seed

script: vendor/bin/phpunit

make sure you have .env.travis